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:
For example, if you enter amount 1000 , annual interest rate 3.25% , and number
of years 1 , the future investment value is 1032.98 .
Solution:
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
double investmentAmount, annualInterestRate;
int numberOfYears;
double monthlyInterestRate, futureInvestmentValue;
System.out.print("Enter investment amount:");
investmentAmount = s.nextDouble();
System.out.print("Enter annual interest rate in percentage:");
annualInterestRate = s.nextDouble();
System.out.print("Enter number of years:");
numberOfYears = s.nextInt();
futureInvestmentValue = investmentAmount * Math.pow((1 + annualInterestRate/1200), numberOfYears * 12);
System.out.print("Accumulated value is $" + futureInvestmentValue);
}
No comments:
Post a Comment