This is a java class on the eclipse Use a twodismensional array Futue Vale Calcu
ID: 3785546 • Letter: T
Question
This is a java class on the eclipse
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
Explanation / Answer
//FutureCalculation.java
import java.util.Scanner;
import java.text.NumberFormat;
public class FutureCalculation
{
public static double getFutureValue(double investment_monthly,double monthly_rate, int totalMonths)
{
double value = 0;
for (int i = 1; i <= totalMonths; i++)
{
value =(value + investment_monthly) *(1 + monthly_rate);
}
return value;
}
public static void main(String[] args)
{
String[][] array = new String [10][4];
int idx = 0;
Scanner sc = new Scanner(System.in);
String again = "y";
while (again.equalsIgnoreCase("y"))
{
System.out.print("Enter monthly investment: ");
double investment_monthly = sc.nextDouble();
System.out.print("Enter yearly interest rate: ");
double intrest_Rate = sc.nextDouble();
System.out.print("Enter number of years: ");
int total_Years = sc.nextInt();
double monthly_rate = intrest_Rate/12/100;
int totalMonths = total_Years * 12;
double futureValue = getFutureValue(investment_monthly, monthly_rate, totalMonths);
NumberFormat c = NumberFormat.getCurrencyInstance();
NumberFormat p = NumberFormat.getPercentInstance();
p.setMinimumFractionDigits(1);
String finalresult ="Monthly investment: "+ c.format(investment_monthly) + " Yearly interest rate: "+ p.format(intrest_Rate/100) + " Number of years: "+ total_Years + " Future value: "+ c.format(futureValue) + " ";
System.out.println(" RESULT: ");
System.out.println(finalresult);
array[idx][0] = Double.toString(investment_monthly);
array[idx][1] = Double.toString(intrest_Rate);
array[idx][2] = Integer.toString(total_Years);
array[idx][3] = Double.toString(futureValue);
System.out.print("Continue? (y/n): ");
again = sc.next();
idx++;
System.out.println();
if(idx == 10)
break;
}
}
}
/*
Output:
Enter monthly investment: 100
Enter yearly interest rate: 8
Enter number of years: 10
RESULT:
Monthly investment: Rs.100.00
Yearly interest rate: 8.0%
Number of years: 10
Future value: Rs.18,416.57
Continue? (y/n): y
Enter monthly investment: 125
Enter yearly interest rate: 8
Enter number of years: 10
RESULT:
Monthly investment: Rs.125.00
Yearly interest rate: 8.0%
Number of years: 10
Future value: Rs.23,020.71
Continue? (y/n): y
Enter monthly investment: 150
Enter yearly interest rate: 8
Enter number of years: 10
RESULT:
Monthly investment: Rs.150.00
Yearly interest rate: 8.0%
Number of years: 10
Future value: Rs.27,624.85
Continue? (y/n): n
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.