Question: write the code for a gui for the following java program import java.util.Scanner; public class RetirementCalculator { public static void main(String[] args) { Scanner scanner

write the code for a gui for the following java program

import java.util.Scanner;

public class RetirementCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// Gather user input

System.out.print("Enter client name: ");

String name = scanner.nextLine();

System.out.print("Enter retirement scenario name: ");

String scenarioName = scanner.nextLine();

System.out.print("Enter current retirement nest egg ($): ");

double nestEgg = scanner.nextDouble();

System.out.print("Enter average annual rate of return (%): ");

double rateOfReturn = scanner.nextDouble() / 100;

System.out.print("Enter current salary ($): ");

double currentSalary = scanner.nextDouble();

System.out.print("Enter yearly contribution amount ($): ");

double yearlyContribution = scanner.nextDouble();

System.out.print("Enter yearly salary increase (%): ");

double yearlySalaryIncrease = scanner.nextDouble() / 100;

System.out.print("Enter number of years to retirement: ");

int yearsToRetirement = scanner.nextInt();

System.out.print("Enter desired income at retirement for active years ($/year): ");

double activeYearsIncome = scanner.nextDouble();

System.out.print("Enter desired income at retirement after active years ($/year): ");

double postActiveYearsIncome = scanner.nextDouble();

// Calculate retirement data

double totalContribution = 0;

double totalInterestEarned = 0;

double yearlyWithdrawal = activeYearsIncome;

double postActiveWithdrawal = postActiveYearsIncome;

int retirementYear = 2023 + yearsToRetirement;

for (int year = 2023; year < retirementYear; year++) {

// Calculate interest earned

double interestEarned = nestEgg * rateOfReturn;

totalInterestEarned += interestEarned;

// Calculate contribution

totalContribution += yearlyContribution;

yearlyContribution *= (1 + yearlySalaryIncrease);

// Update nest egg balance

nestEgg += interestEarned + yearlyContribution;

// Update withdrawal amounts

if (year >= 65 && year <= 80) {

yearlyWithdrawal = activeYearsIncome;

} else if (year > 80) {

postActiveWithdrawal = postActiveYearsIncome;

}

}

// Print retirement data

System.out.println(" Retirement data for " + name + " (" + scenarioName + "): ");

System.out.printf("Total contribution: $%,.2f ", totalContribution);

System.out.printf("Total interest earned: $%,.2f ", totalInterestEarned);

System.out.printf(" Yearly withdrawal: ");

System.out.printf("Active years: $%,.2f ", yearlyWithdrawal);

System.out.printf("Post-active years: $%,.2f ", postActiveWithdrawal);

scanner.close();

}

}

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!