Asked by anonymous
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?
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?
Answers
Answered by
anonymous
this is the assignment question:
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.
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.
Answered by
Ms Pi 3.14159265358979323
Check for commas, colons and extra spaces : )
Answered by
anonymous
I got the error, it was:
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);
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);
Answered by
anonymous
can someone the code if its good?
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);
}
}
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);
}
}
Answered by
oobleck
yes, someone can check it -- you!
Run the dang program and see whether it produces the correct result!
Run the dang program and see whether it produces the correct result!
There are no AI answers yet. The ability to request AI answers is coming soon!