packagechapter3.Retirement;importjava.util.Scanner;publicclassRetirement{publicstaticvoidmain(String[] args){Scanner in =newScanner(System.in);System.out.print("How much money do you need to retire? ");double goal = in.nextDouble();System.out.print("How much money will you contribute every year? ");double payment = in.nextDouble();System.out.print("Interest rate in %: ");double interestRate = in.nextDouble();double balance =0;int years =0;while(balance < goal){
balance += payment;double interest =balance * interestRate /100;
balance += interest;
years++;}System.out.println("You can retire in "+years+" years.");}}
packagechapter3.Retirement2;importjava.util.Scanner;publicclassRetirement2{publicstaticvoidmain(String[] args){Scanner in =newScanner(System.in);System.out.print("How much money will you contribute every year? ");double payment = in.nextDouble();System.out.print("Interest rate in %: ");double interestRate = in.nextDouble();double balance =0;int year =0;String input;do{
balance += payment;double interest = balance * interestRate /100;
balance += interest;
year++;System.out.printf("After year %d, your balance is %,.2f%n",year,balance);System.out.print("Ready to retire?(Y/N) ");
input = in.next();}while(input.equals("N"));}}