Hi, there were few errors which you can see by comparing your code with mine.
This is my code:
CODE
import java.util.Scanner;
public class Investment
{
public static void main (String []args)
{
double principal;
double rate;
int years;
Scanner input = new Scanner (System.in);
System.out.print("Enter the intial investment amount:");
principal = input.nextDouble();
System.out.print("Enter the annual interest rate:");
rate = input.nextDouble();
System.out.print("Enter number of years:");
years = input.nextInt();
double monthlyInterestRate;
monthlyInterestRate = rate/1200;
double futureValue;
futureValue = principal*Math.pow((1+monthlyInterestRate),years*12);
System.out.println("The future value is " +futureValue);
}
}
Now a little comment to your code:
You have to
import java.util.Scanner; in order
Scanner input = new Scanner (System.in); to work.
Instead of
System.ini there should be
System.inOnce you declare the variables there is no need to do that again.
e.g.
QUOTE
int years;
int years = input.nextInt();
is not going to work.
you use
QUOTE
monthlyInterestRate = annualInterestRate/1200;
annualInterestRate is not declared, but
rate is therefore
rate should be instead of
annualInterestRate.
And the last but not least :
QUOTE
futureValue = principal*Math.pow((1+monthlyInterestRate),number of years*12);
number of years is not declared variable, even if you declare it you'll get an error because of the name. So you could declare it like double
numbers_of years. But in this case you don't need to because you already have
yearsso that line should be:
CODE
futureValue = principal*Math.pow((1+monthlyInterestRate),years*12);
As I said compare your code with mine.