Question: Make a application that prompts a user for the number of years the user has until retirement and then the amount of money the user
Make a application that prompts a user for the number of years the user has until retirement and then the amount of money the user can save annually. If the user enters 0 or a negative number for either value, reprompt the user until valid entries are made. Assume that no interest is earned on the money. Display the amount of money the user will have at retirement
import java.util.Scanner;
public class RetirementGoal
{
public static void main (String[] args)
{
//put code here
}
}
2, Modify the RetirementGoal application to display the amount of money the user will have if the user earns 4% interest on the balance every year.
import java.util.Scanner;
public class RetirementGoal2
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
int years;
int saveAmount;
int total;
final double RATE;
// perform interest calculation
System.out.print("How many years until retirement? >> ");
years = input.nextInt();
while(years <= 0)
{
System.out.println("Years cannot be 0 or negative");
System.out.print("Please renter years >> ");
years = input.nextInt();
}
System.out.print("How much can you save annually? >> ");
saveAmount = input.nextInt();
while(saveAmount <= 0)
{
System.out.println("Amount cannot be 0 or negative");
System.out.print("Please renter amount to save annually >> ");
saveAmount = input.nextInt();
}
total = saveAmount * years;
System.out.println("If you save $" + saveAmount +
" for " + years + " years without interest, you will have $" + total);
double total2 = 0;
for(int y = 0; y < years; ++y)
{
total2 += saveAmount;
}
System.out.println("If you save $" + saveAmount +
" for " + years + " years, with " + (RATE * 100) +
"% interest, you will have $" + total2);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
