Compute future investment value at a given interest rate for a specified number of years


This Java program calculates the future value of an investment based on the investment amount, rate of interest, and number of years using the formula FV = PV * (1 + r)^n, where FV is the future value, PV is the present value (investment amount), r is the monthly interest rate, and n is the number of months. Here's how the program works:

  • The program starts by prompting the user to enter the investment amount, rate of interest, and number of years using the Scanner class.
  • The program calculates the monthly interest rate by multiplying the annual rate by 0.01 and dividing it by 12.
  • The program then uses a for loop to iterate through each year and calculates the future value of the investment using the future_Value function, which takes in the investment amount, monthly interest rate, and number of years as parameters.
  • Inside the loop, the program uses System.out.printf to print the year and the corresponding future value with a formatted width of 19 if the year is less than 10, or 18 if the year is 10 or greater.
  • Finally, the future_Value function returns the calculated future value to the main program.

Source Code

import java.util.Scanner;
public class Future_Investmen
{ 
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in); 
		System.out.print("Enter the Investment Amount : ");
		double inves = in.nextDouble();
		System.out.print("Enter the Rate of Interest : ");
		double rate = in.nextDouble();
		System.out.print("Enter Number of Years: ");
		int year = in.nextInt();
 
		rate *= 0.01;
 
		System.out.println("\nYears      FutureValue");
		System.out.println("-----------------------");
		for(int i = 1; i <= year; i++)
		{
		int format = 19;
			if (i >= 10)
				format = 18;
			System.out.printf(i + "%"+format+".2f\n", future_Value(inves, rate/12, i));
		}
	 }
 
	public static double future_Value(double inves_amt, double mon_inv_rate, int years)
	{
		return inves_amt * Math.pow(1 + mon_inv_rate, years * 12);
	}
}

Output

Enter the Investment Amount : 8500
Enter the Rate of Interest : 56
Enter Number of Years: 6

Years      FutureValue
-----------------------
1           14693.31
2           25399.22
3           43905.72
4           75896.51
5          131196.58
6          226789.66

Example Programs