public class FutureInvestmentValue {
public static void main(String[] args) {
Scanner input= new Scanner (System.in);
System.out.print("Enter investment amount: ");
double investmentAmount = input.nextDouble();
System.out.print("Enter annual interest rate: ");
double annualInterestRate = input.nextDouble();
System.out.print("Enter the number of years: ");
double years = input.nextDouble();
double monthlyInterestRate = (annualInterestRate)/1200;
double investmentValuepart1 = (1 +monthlyInterestRate);
double investmentValuepart2 = (years *12);
double investmentValuepart3 = Math.pow(investmentValuepart1, investmentValuepart2);
double futureInvestmentValue = investmentAmount*investmentValuepart3;
System.out.printf("Accumulated value is: %.2f"+futureInvestmentValue);
}
}
the inputs work fine but when this program is displaying futureInvestmentValue, it gives an error. can someone help find the error?
5 answers
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:
and displays the future investment value using the following formula:
futureInvestmentValue =
investmentAmount * (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.
Hint: Use the Math.pow(a, b) method to compute a raised to the power of b.
System.out.printf("Accumulated value is: %.2f"+futureInvestmentValue);
the plus sign that is in front of futureInvestmentValue should be comma like
System.out.printf("Accumulated value is: %.2f",futureInvestmentValue);
public class FutureInvestmentValue {
public static void main(String[] args) {
Scanner input= new Scanner (System.in);
System.out.print("Enter investment amount: ");
double investmentAmount = input.nextDouble();
System.out.print("Enter annual interest rate: ");
double annualInterestRate = input.nextDouble();
System.out.print("Enter the number of years: ");
double years = input.nextDouble();
double monthlyInterestRate = (annualInterestRate)/1200;
double investmentValuepart1 = (1 +monthlyInterestRate);
double investmentValuepart2 = (years *12);
double investmentValuepart3 = Math.pow(investmentValuepart1, investmentValuepart2);
double futureInvestmentValue = investmentAmount*investmentValuepart3;
System.out.printf("Accumulated value is: %.2f", futureInvestmentValue);
}
}
Run the dang program and see whether it produces the correct result!