The problem 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 x (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. The java snippet below shows the output of the program:
Enter investment amount: 1000
Enter annual interest rate in percentage: 4.25
Enter number of years: 1
Accumulated value is $1043.34
Breaking it down public static void main ( String [] Strings ) {
Scanner input = new Scanner ( System . in );
System . out . print ( "Enter investment amount: " );
double investmentAmount = input . nextDouble ();
System . out . print ( "Enter annual interest rate in percentage: " );
double annualInterestRate = input . nextDouble () / 100 ;
System . out . print ( "Enter number of years: " );
double years = input . nextDouble ();
input . close ();
double futureInvestmentValue = calculateFutureInvestment (
investmentAmount , annualInterestRate , years );
System . out . print ( "Accumulated value is $" + futureInvestmentValue );
}
private static double calculateFutureInvestment ( double investmentAmount ,
double annualInterestRate , double years ) {
double futureInvestmentValue = investmentAmount
* Math . pow (( 1 + ( annualInterestRate / 12 )), ( years * 12 ));
return futureInvestmentValue ;
}
Output Enter investment amount: 100
Enter annual interest rate in percentage: 4.25
Enter number of years: 1
Accumulated value is < class="33377163096169"></>
Calculate future investment value posted by Justin Musgrove on 05 April 2016
Tagged: java, java-exercises-beginner, intro-to-java-10th-edition, and ch2
Share on: Facebook Google+