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

Project: Calculating Future Investment Value Problem Description: Write a progra

ID: 3850173 • Letter: P

Question

Project: Calculating Future Investment Value

Problem Description:

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 (Note that we are compounding on a monthly basis instead of a yearly basis):

futureInvestmentValue = investmentAmount * (1 + monthlyInterestRate)numberOfMonths

monthlyInterestRate = annualInterestRate/12

For example, if you enter amount 1000, annual interest rate 3.25% (3.25/100), and number of years 1, the future investment value is approximately 1032.99.

Here is a sample run:

Sample:

Enter investment amount: 1000

Enter annual interest rate (in percentage points): 3.25

Enter number of years: 1

Accumulated value is: 1032.9885118105894

What to deliver?

Your .java file including:

1. A sample run at the top with investment amount of 3000, annual interest rate of 5.5%, and 3 years. These should be commented. (2 points)

2. Your code with other appropriate comments. (Code: 5 points, Comments: 3 points)

Hint:

1. CalculateProducts.java in the Classroom Example folder at eLearning provides a good example of a deliverable. It has both the sample run commented and we can run the java file without changing the file.

2. Hint: Use the Math.pow(x, y) method to compute x raised to the power of y.

3. Use the sample run in the instruction to test your program to make sure it is correct before you submit it.

Explanation / Answer

import java.util.Scanner;

/**
* @author
*
*/
public class CalculateProducts {

   /**
   * method to get future investment value
   *
   * @param investmentAmount
   * @param annualInterestRate
   * @param noOfYears
   * @return
   */
   public static double getFutureInvestmentValue(double investmentAmount,
           double annualInterestRate, int noOfYears) {

       double monthlyInterestRate = (annualInterestRate / 100.00) / 12;
       int numberOfMonths = noOfYears * 12;
       double futureInvestmentValue = investmentAmount
               * Math.pow((1 + monthlyInterestRate), numberOfMonths);
       return futureInvestmentValue;
   }

   public static void main(String[] args) {

       Scanner scanner = null;
       try {
           // declaration
           scanner = new Scanner(System.in);

           // prompt to get input from console
           System.out.print("Enter investment amount: ");
           double investmentAmount = scanner.nextDouble();

           System.out
                   .print("Enter annual interest rate (in percentage points): ");
           double annualInterestRate = scanner.nextDouble();

           System.out.print("Enter number of years: ");
           int noOfYears = scanner.nextInt();

           // printing the Accumulated value
           System.out.println("Accumulated value is: "
                   + getFutureInvestmentValue(investmentAmount,
                           annualInterestRate, noOfYears));

       } catch (Exception e) {
           // TODO: handle exception
       } finally {
           if (scanner != null)
               scanner.close();
       }
   }
}

OUTPUT:

Enter investment amount: 3000
Enter annual interest rate (in percentage points): 5.5
Enter number of years: 3
Accumulated value is: 3536.845807384803

Enter investment amount: 1000
Enter annual interest rate (in percentage points): 3.25
Enter number of years: 1
Accumulated value is: 1032.9885118105894