Include one additional user input, the percentage by which the extra contribution should be increased each year. For example, suppose the user wants tocontribute$1000 the first year, with a 2% annual increase. At the end of year 1,$1000 would be added to the account. At the end of year 2, the extra amount grows by 2%, so$1020 would be added to the account. At the end of year 3, the extra amount grows by another 2% so $1040.40 would be added to the account, etc. I'm having trouble with the attached code, can anyone help me out?
import java.util.Scanner;
public class GettingRichSlowly {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Get user input for initial deposit, annual interest rate,
// number of years, amount of yearly extra contribution
System.out.println("Enter initial deposit: ");
double initialDeposit = scnr.nextDouble();
System.out.println("Enter annual interest rate (as a percentage): ");
double interestRate = scnr.nextDouble();
System.out.println("Enter number of years: ");
int years = scnr.nextInt();
System.out.println("How much extra would you like to contribute at the end of each year? ");
double extraAmount = scnr.nextDouble();
System.out.println("How much should the annual contribution increase each year (as a percentage)?");
double annualIncrease = scnr.nextDouble();
annualIncrease = annualIncrease / 100 + 1;
// Amount in the account at the beginning of the current year
double yearStart = initialDeposit;
// Repeat years number of times
int i = 1;
while (i <= years) {
// Dollar amount of interest earned during the current year
double interest = yearStart * interestRate / 100;
if (i == 1) {
double yearEnd = yearStart + interest + extraAmount;
}
else {
extraAmount = extraAmount * annualIncrease;
double yearEnd = yearStart + interest + extraAmount;
}
// Show the results for the current year
System.out.format("%3d\t$%12.2f\t$%12.2f\t$%12.2f\t$%12.2f\n", i, yearStart, interest, extraAmount, yearEnd);
// Update yearStart for the following year
yearStart = yearEnd;
i++;
}
}
}
edit: there are several error messages I get when running this code with the input 100, 7.5, 10, 1000, 5. GettingRichSlowly.java:44: cannot find symbol symbol : variable yearEnd location: class GettingRichSlowly System.out.format("%3d\t$%12.2f\t$%12.2f\t$%12.2f\t$%12.2f\n", i, yearStart, interest, extraAmount, yearEnd); ^ GettingRichSlowly.java:47: cannot find symbol symbol : variable yearEnd location: class GettingRichSlowly yearStart = yearEnd; What do these mean?