Java programs to calculate the future investment value – In this particular article, we will brief in on the various ways to calculate the future investment value in Java Programming.
Suitable examples and sample programs are added for the better understanding of the people who are interested in this specific article. The compiler has also been added where you can execute the programs by yourself.
The methods used in this particular piece are as follows:
- Taking Input From Scanner Class
- Taking Input From Command-line Arguments
- Using Separate “fiv” Calculation class
- Using Static Function
Future Investment Value or simply, Future Value is the worth of an asset at a given point in time. The value that determines the value at that particular time period are:
- Interest Rate or
- Rate of Return
As you can see, this is the formula for calculating the Future Investment Value. PV is known as the Present Value or simply the Principal.
The (1 + i)^n is regarded as the Accumulation function which determines the appreciation or depreciation of the said asset.
“i” = The interest paid by the investment.
“n” or “y” = the time in years the investment is held.
Thus, the methods used to calculate the Future Investment Value in Java Programming are as follows:
Taking Input From Scanner Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.lang.*; import java.util.Scanner; class FIV { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter present value: "); double p=sc.nextInt(); System.out.print("Enter the interest rate: "); double r=sc.nextInt(); System.out.print("Enter the time period in years: "); double y=sc.nextInt(); double f=p*Math.pow((1+r/100),y); System.out.print("value is: "+f); } } |
1 2 3 4 5 6 7 8 9 10 11 |
Enter present value: 1000 Enter the interest rate: 10 Enter the time period in years: 2 value is: 1210.0000000000002 Enter present value: 10000 Enter the interest rate: 1 Enter the time period in years: 10 value is: 11046.221254112046 |
Taking Input From Command Line Arguments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.lang.*; class FutureInvestmentValue { public static void main(String args[]) { double p=Double.parseDouble(args[0]); System.out.println("present value is : "+p); double r=Double.parseDouble(args[1]); System.out.println("Interest rate is : "+r); double y=Double.parseDouble(args[2]); System.out.println("Time period in years is: "+y); double f=p*Math.pow((1+r/100),y); System.out.println("Future Investment Value is: "+f); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
>java FutureInvestmentValue 10000 1 10 present value is : 10000.0 Interest rate is : 1.0 Time period in years is: 10.0 Future Investment Value is: 11046.221254112046 output:2 >java FutureInvestmentValue 10000 2 10 present value is : 10000.0 Interest rate is : 2.0 Time period in years is: 10.0 Future Investment Value is: 12189.944199947573 output:3 >java FutureInvestmentValue 10000 3 10 present value is : 10000.0 Interest rate is : 3.0 Time period in years is: 10.0 Future Investment Value is: 13439.163793441223 |
Using Separate fiv Calculation class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import java.util.*; import java.util.Scanner; class FIVCalculation { double fiv; FIVCalculation(double p,double r,double y) { fiv=p*Math.pow((1+r/100),y); } } class FIV { public static void main(String []args) { Scanner sc = new Scanner(System.in); System.out.print("Enter present value: "); double p=sc.nextInt(); System.out.print("Enter the interest rate: "); double r=sc.nextInt(); System.out.print("Enter the time period in years: "); double y=sc.nextInt(); FIVCalculation e= new FIVCalculation(p,r,y); System.out.print("value is:= "+e.fiv+"\n"); } } |
1 2 3 4 5 6 7 |
Enter present value: 20000 Enter the interest rate: 20 Enter the time period in years: 20 value is:= 766751.9984894944 |
Using Static Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import java.util.*; import java.util.Scanner; class FutureInvestmentValue { public static void main(String []args) { Scanner sc = new Scanner(System.in); System.out.print("Enter present value: "); double p=sc.nextInt(); System.out.print("Enter the interest rate: "); double r=sc.nextInt(); System.out.print("Enter the time period in years: "); double y=sc.nextInt(); double e= FIVCalculation(p,r,y); System.out.print("value is:= "+e+"\n"); } static double FIVCalculation(double p,double r,double y) { double fiv=p*Math.pow((1+r/100),y); return fiv; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
output:1 Enter present value: 1000 Enter the interest rate: 10 Enter the time period in years: 1 value is:= 1100.0 output:2 Enter present value: 10000 Enter the interest rate: 10 Enter the time period in years: 1 value is:= 11000.0 output:3 Enter present value: 100000 Enter the interest rate: 10 Enter the time period in years: 1 value is:= 110000.00000000001 |