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

my question is about problem 2.21. i need help trying to solve it Write a progra

ID: 3783441 • Letter: M

Question

my question is about problem 2.21. i need help trying to solve it

Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula: futureInvestmentValue = investmentAmount times (1 + monthlyInterestRate)^numberOfYears*12 For example, if you enter amount 1000. Annual interest rate 3.25%, and number of years 1, the future investment value is 1032.98. Here is a sample run: Enter investment amount: 1000 Enter annual interest rate in percentage: 4.25 Enter number of years: 1 Accumulated value is $1043.34

Explanation / Answer

Answer.

The idea is to convert yearly interest rate to monthly interest rate. We can do that using following formula:

Monthly interest rate = Yearly interest rate / (12 * 100)

Please find the java program below:

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

import java.util.Scanner;

public class FutureInvestment {

   public static void main(String args[]){
       Scanner scanner = new Scanner(System.in);
       System.out.println("Enter investment amount: ");
       double amount = scanner.nextDouble();
      
       System.out.println("Enter annual interest rate in percentage: ");
       double interest = scanner.nextDouble();
      
       System.out.println("Enter number of years: ");
       double time = scanner.nextInt();
       double futureInvestment = 0;
      
       /*
       * Convert yearly interest rate to monthly using formula:
       *
       * monthly rate = yearly rate / (12 * 100)
       *
       */
       double a = 1 + (interest / 1200);
       double b = time * 12;
       double c = Math.pow(a, b);
       futureInvestment = amount * c;
       double result = Math.round(futureInvestment * 100) / 100D;
       System.out.println("Accumulated value is: $" + result);
      
   }
  
}

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