Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is what I have so far: public class FutureValueApp { public static void mai

ID: 3654994 • Letter: T

Question

This is what I have so far: 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 Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDoubleWithinRange(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 30); int years = getIntWithinRange(sc, "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: " + currency.format(monthlyInvestment) + " " + "Yearly interest rate: " + percent.format(interestRate/100) + " " + "Number of years: " + years + " " + "Future value: " + 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 System.out.print("Continue? (y/n): "); choice = sc.next(); System.out.println(); } } public static double getDouble(Scanner sc, String prompt) { boolean isValid = false; double d = 0; while (isValid == false) { System.out.print(prompt); if (sc.hasNextDouble()) { d = sc.nextDouble(); isValid = true; } else { System.out.println("Error! Invalid decimal value. Try again."); } sc.nextLine(); // discard any other data entered on the line } return d; } public static double getDoubleWithinRange(Scanner sc, String prompt, double min, double max) { double d = 0; boolean isValid = false; while (isValid == false) { d = getDouble(sc, prompt); if (d <= min) System.out.println( "Error! Number must be greater than " + min + "."); else if (d >= max) System.out.println( "Error! Number must be less than " + max + "."); else isValid = true; } return d; } public static int getInt(Scanner sc, String prompt) { boolean isValidInt = false; int i = 0; while (isValidInt == false) { System.out.print(prompt); if (sc.hasNextInt()) { i = sc.nextInt(); isValidInt = true; } else { System.out.println("Error! Invalid integer value. Try again."); } sc.nextLine(); // discard any other data entered on the line } return i; } public static int getIntWithinRange(Scanner sc, String prompt, int min, int max) { int i = 0; boolean isValid = false; while (isValid == false) { i = getInt(sc, prompt); if (i <= min) System.out.println( "Error! Number must be greater than " + min + "."); else if (i >= max) System.out.println( "Error! Number must be less than " + max + "."); else isValid = true; } return i; } public static double calculateFutureValue(double monthlyInvestment, double monthlyInterestRate, int months) { double futureValue = 0; for (int i = 1; i <= months; i++) { futureValue = (futureValue + monthlyInvestment) * (1 + monthlyInterestRate); } return futureValue; } } What is needed is to: 1. Declare a variable at the beginning of the main method for a linked lits that stores strings. 2. After the code that calculates, formats and displays the results for each calculation, add code that formats a string with the results of the calculation and then stores the string in the linked list. 3. Add code to display the elements in the linked list at the console when the user indicates that the program should end. This code should retrieve the elements of the linked list in reverse order. To do that, you

Explanation / Answer

All task that you told is now completed.....you may also download the code from http://www.2shared.com/file/_txyg3pX/FutureValueApp.html import java.text.NumberFormat; import java.util.Iterator; import java.util.LinkedList; import java.util.Scanner; public class FutureValueApp { public static void main(String[] args) { LinkedList list=new LinkedList(); // display a welcome message System.out.println("Welcome to the Future Value Calculator"); System.out.println(); // perform 1 or more calculations Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDoubleWithinRange(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 30); int years = getIntWithinRange(sc, "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: " + currency.format(monthlyInvestment) + " " + "Yearly interest rate: " + percent.format(interestRate/100) + " " + "Number of years: " + years + " " + "Future value: " + currency.format(futureValue) + " "; list.add(results); // print the results System.out.println(); System.out.println("FORMATTED RESULTS"); System.out.println(results); // see if the user wants to continue System.out.print("Continue? (y/n): "); choice = sc.next(); System.out.println(); } Iterator ilist=list.iterator(); while(ilist.hasNext()){ System.out.println(ilist.next()); } } public static double getDouble(Scanner sc, String prompt) { boolean isValid = false; double d = 0; while (isValid == false) { System.out.print(prompt); if (sc.hasNextDouble()) { d = sc.nextDouble(); isValid = true; } else { System.out.println("Error! Invalid decimal value. Try again."); } sc.nextLine(); // discard any other data entered on the line } return d; } public static double getDoubleWithinRange(Scanner sc, String prompt, double min, double max) { double d = 0; boolean isValid = false; while (isValid == false) { d = getDouble(sc, prompt); if (d = max) System.out.println( "Error! Number must be less than " + max + "."); else isValid = true; } return d; } public static int getInt(Scanner sc, String prompt) { boolean isValidInt = false; int i = 0; while (isValidInt == false) { System.out.print(prompt); if (sc.hasNextInt()) { i = sc.nextInt(); isValidInt = true; } else { System.out.println("Error! Invalid integer value. Try again."); } sc.nextLine(); // discard any other data entered on the line } return i; } public static int getIntWithinRange(Scanner sc, String prompt, int min, int max) { int i = 0; boolean isValid = false; while (isValid == false) { i = getInt(sc, prompt); if (i = max) System.out.println( "Error! Number must be less than " + max + "."); else isValid = true; } return i; } public static double calculateFutureValue(double monthlyInvestment, double monthlyInterestRate, int months) { double futureValue = 0; for (int i = 1; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote