Question: A. Write an application that prompts a user for the number of years the user has until retirement and then the amount of money the

A. Write an 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.

B. 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.

I already did part A I just need help with part B.

Code for A:

import java.util.Scanner; public class RetirementGoal { public static void main(String a[]) { Scanner s=new Scanner(System.in); int years; double savings; System.out.println(" number of years the user has until retirement"); years=s.nextInt(); while(years<=0) { System.out.println(" please enter a valid number"); years=s.nextInt(); } System.out.println(" enter amount of money you can save anually"); savings=s.nextDouble(); while(savings<=0) { System.out.println(" please enter a valid number"); savings=s.nextDouble(); } System.out.println("Total savings after "+years+ "years = "+savings*years); }

}

Given code for B:

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!