In: Computer Science
Modify the RetirementGoalapplication to display the amount of money the user will have if the user earns 4%interest on the balance every year. In java pls
given code.
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);
}
}
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 = 0.04; // 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 + total2) * (1 + RATE); } System.out.println("If you save $" + saveAmount + " for " + years + " years, with " + (RATE * 100) + "% interest, you will have $" + total2); } }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.