# Exercise 2.21 - Financial Application: Calculate Future Investment Value

The program below is the solution to Liang's Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.21.

```/**
*
* @Author: Aghatise Osazuwa
* Website: www.cscprogrammingtutorials.com
*
* Exercise 2.21 - Financial application: calculate future investment value
*
*/

import java.util.Scanner;

public class Ex02_21 {

public static void main(String[] args) {

// Display Program Information
System.out.println("This Program Calculates The Future Investment Value"
+ " of Investment.\n");

// create Scanner
Scanner input = new Scanner(System.in);

// prompt user to enter details
System.out.println("Enter investment amount:");
double investmentAmount = input.nextDouble();
System.out.println("Enter annual interest rate in percentage:");
double monthlyInterestRate = input.nextDouble();
System.out.println("Enter number of years:");
double numberOfYears = input.nextDouble();

// calculate s using the formula futureInvestmentValue =
// investmentAmount x (1 + monthlyInterestRate)^numberOfYears*12
double futureInvestmentValue =
investmentAmount * Math.pow((1 + (monthlyInterestRate / 1200)), (numberOfYears * 12));
// format futureInvestmentValue to two decimal places
futureInvestmentValue = (int) (futureInvestmentValue * 100) / 100.0;

// display the result
System.out.println("Accumulated value is \$" + futureInvestmentValue + "\n");
}
}
```
 Program output