Question: Modify the application 1. Open the Main class. Within the while loop, use the increment operator (++) to increment the counter variable named i. 2.

Modify the application

1. Open the Main class. Within the while loop, use the increment operator (++) to increment the counter variable named i.

2. Combine the first three statements in the while loop into a single statement that calculates the future value. To get this to work, you can use parentheses to control the order of precedence of the operations. (First, add the monthly investment. Then, add the monthly interest.)

3. Run the application to make sure it still works correctly.

Add a yearly fee

4. Before the while loop, declare a constant that stores a yearly fee of $50.

5. Within the while loop, add an if statement that uses the modulus operator to check whether the current month is a multiple of 12. If so, subtract the yearly fee from the future value.

6. After the while loop, add a statement that applies currency formatting to the yearly fee and prints it to the console.

---------------------------

package murach.fv;

import java.text.NumberFormat; import java.util.Scanner;

public class Main {

public static void main(String[] args) { // display a welcome message System.out.println("Welcome to the Future Value Calculator"); System.out.println();

Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) {

// get input from user System.out.print("Enter monthly investment: "); double monthlyInvestment = Double.parseDouble(sc.nextLine());

System.out.print("Enter yearly interest rate: "); double yearlyInterestRate = Double.parseDouble(sc.nextLine());

System.out.print("Enter number of years: "); int years = Integer.parseInt(sc.nextLine()); // convert yearly values to monthly values double monthlyInterestRate = yearlyInterestRate / 12 / 100; int months = years * 12;

// calculate the future value double futureValue = 0; int i = 1; while (i <= months) { futureValue = futureValue + monthlyInvestment; double monthlyInterestAmount = futureValue * monthlyInterestRate; futureValue = futureValue + monthlyInterestAmount; i = i + 1; }

// format and display the result System.out.println("Future value: " + NumberFormat.getCurrencyInstance().format(futureValue)); System.out.println();

// see if the user wants to continue System.out.print("Continue? (y/n): "); choice = sc.nextLine(); System.out.println(); } System.out.println("Bye!"); } }

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!