Question: project ch11_ex2_FutureValue includes the two classes below FutureValueApp.java import java.text.*; public class FutureValueApp { public static void main(String[] args) { // display a welcome message

 project ch11_ex2_FutureValue includes the two classes below FutureValueApp.java import java.text.*; public

project ch11_ex2_FutureValue includes the two classes below

FutureValueApp.java

import java.text.*;

public class FutureValueApp {

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

// perform 1 or more calculations String choice = "y"; while (choice.equalsIgnoreCase("y")) {

// get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = Console.getDouble( "Enter monthly investment: ", 0, 1000); double interestRate = Console.getDouble( "Enter yearly interest rate: ", 0, 30); int years = Console.getInt( "Enter number of years: ", 0, 100);

// calculate the future value double monthlyInterestRate = interestRate / 12 / 100; int months = years * 12; double futureValue = calculateFutureValue( monthlyInvestment, monthlyInterestRate, months);

// get the currency and percent formatters NumberFormat currency = NumberFormat.getCurrencyInstance(); NumberFormat percent = NumberFormat.getPercentInstance(); percent.setMinimumFractionDigits(1);

// format the result as a single string String results = "Monthly investment:\t" + currency.format(monthlyInvestment) + " " + "Yearly interest rate:\t" + percent.format(interestRate / 100) + " " + "Number of years:\t" + years + " " + "Future value:\t\t" + currency.format(futureValue) + " ";

// print the results System.out.println(); System.out.println("FORMATTED RESULTS"); System.out.println(results);

// see if the user wants to continue choice = Console.getString("Continue? (y): "); System.out.println(); } }

public static double calculateFutureValue(double monthlyInvestment, double monthlyInterestRate, int months) { double futureValue = 0; for (int i = 1; i

Console.java

import java.util.Scanner;

public class Console { private static Scanner sc = new Scanner(System.in);

public static String getString(String prompt) { System.out.print(prompt); String s = sc.next(); // read user entry sc.nextLine(); // discard any other data entered on the line return s; }

public static int getInt(String prompt) { int i = 0; boolean isValid = false; while (!isValid) { System.out.print(prompt); if (sc.hasNextInt()) { i = sc.nextInt(); isValid = true; } else { System.out.println("Error! Invalid integer. Try again."); } sc.nextLine(); // discard any other data entered on the line } return i; }

public static int getInt(String prompt, int min, int max) { int i = 0; boolean isValid = false; while (!isValid) { i = getInt(prompt); if (i = max) { System.out.println( "Error! Number must be less than " + max + "."); } else { isValid = true; } } return i; }

public static double getDouble(String prompt) { double d = 0; boolean isValid = false; while (!isValid) { System.out.print(prompt); if (sc.hasNextDouble()) { d = sc.nextDouble(); isValid = true; } else { System.out.println("Error! Invalid number. Try again."); } sc.nextLine(); // discard any other data entered on the line } return d; }

public static double getDouble(String prompt, double min, double max) { double d = 0; boolean isValid = false; while (!isValid) { d = getDouble(prompt); if (d = max) { System.out.println( "Error! Number must be less than " + max + "."); } else { isValid = true; } } return d; } }

1. Use proper statement indentation and meaningful variable names in the code.

2. Add a multi-line description of this application that also includes your name and the date written at the beginning of the code.

3. Add appropriate descriptive comments to each line of code you add to the project explaining why the code is in the application.

cise 11-2 Use a rectangular array exercise guides you through the process of adding a rectangular array to This the Future Value application . This array will store the values for up to ten of the calculations that are performed. When the program ends, it will print a summary of those calculations that looks something like this: Future Value Calculations Inv/Mo. Rate $100.00 8.0% $125.00 8.0% $150.00 8.0% Years Future Value 10 10 10 $18,416.57 $23,020.71 $27,624.85 1. Open the project named chl1_ex2_Future Value in the ex_starts directory . en, review the code and run the application to make sure it works correctly. 2. Declare variables at the beginning of the main0 method for a row counter and a rectangular array of strings that provides for 10 rows and 4 columns. After the code that calculates, formats, and displays the results for each calculation, add code that stores the formatted values as strings in the next row of the array. (Hint: You can use the toString0 method of the Integer class to store the years value.) Add code to display the elements in the array at the console when the user indicates that the program should end. The output should be formatted as shown above and should only include the rows that contain data. Then, test the program by making up to 10 future value calculations. 3. 4

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!