Use a twodismensional array Futue Vale Calculations InvMo Ra

Use a twodismensional array

Futue Vale Calculations

Inv/Mo.       Rate      year’s     future value

$100.00       8,0%      10          $18,416.57

#125.00     8.0%        10          $23,020.71

$150.00      8.0%       10          $27,624.85

1- Declare variables at the beginning of the main method for a row counter and a rectangular array of strings that provides for 10 rows and 4 columns

2- After the code that displays the results of each calculation, add code that formats all values for the calculation and converts them to strings. Then, store these string values in the next row of the array. (Hint: you can use the tstring method of the Integer class to convert the year’s value to a string)

3- Add code to display the elements on the console when the user exits the application. The output should be formatted as shown above and should only include the rows that contain data

4- Test the application by making up to 10 futures value calculation

Solution

public static void main(String[] args) { String[][] FutureValueArray = new String [10][4]; int counter = 0; // 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:\\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); FutureValueArray[counter][0] = Double.toString(monthlyInvestment); FutureValueArray[counter][1] = Double.toString(interestRate); FutureValueArray[counter][2] = Integer.toString(years); FutureValueArray[counter][3] = Double.toString(futureValue); for(int i = 0; i < counter; i++) { for (int j = 0; j < FutureValueArray[i].length; j++) System.out.println(FutureValueArray[i][j] + \" \"); System.out.println(\"\ \"); } // see if the user wants to continue System.out.print(\"Continue? (y/n): \"); choice = sc.next(); counter++; System.out.println(); } }
Use a twodismensional array Futue Vale Calculations Inv/Mo. Rate year’s future value $100.00 8,0% 10 $18,416.57 #125.00 8.0% 10 $23,020.71 $150.00 8.0% 10 $27,6

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site