1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2007
Location
Chicago
Posts
4
Rep Power
0

Java compound interest

Hi everyone, I am having difficultly completing a program that calculates compund interest based based on user's input, any help would be appreciated.

Code:
```public class CompoundInterest
{

public static void main(String[] args)
{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the initial investment amount: ");
int amt = sc.nextInt();

System.out.print("Enter the interest rate: ");
int rt = sc.nextInt();

System.out.print("Enter the number of years: ");
int yrs = sc.nextInt();

}

public static double CompoundByPow(double amt, double rt,  int yrs,double finalInterest)
{
//error here  finalInterest = amt* Math.pow((1 + rt)*yrs);

return finalInterest;
}

public static double CompoundByLoop(double amt, double rt, int yrs, double interest)
{
for ( yrs = 0;  yrs > 10;  yrs++ ) {
interest = amt * rt*yrs;
amt += interest;
System.out.println(interest);
}

}
}```
error message
pow(double,double) in java.lang.Math cannot be applied to (double)
finalInterest = amt* Math.pow((1 + rt)*yrs);
2. Originally Posted by mic822
Hi everyone, I am having difficultly completing a program that calculates compund interest based based on user's input, any help would be appreciated.

Code:
```public class CompoundInterest
{

public static void main(String[] args)
{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the initial investment amount: ");
int amt = sc.nextInt();

System.out.print("Enter the interest rate: ");
int rt = sc.nextInt();

System.out.print("Enter the number of years: ");
int yrs = sc.nextInt();

}

public static double CompoundByPow(double amt, double rt,  int yrs,double finalInterest)
{
//error here  finalInterest = amt* Math.pow((1 + rt)*yrs);

return finalInterest;
}

public static double CompoundByLoop(double amt, double rt, int yrs, double interest)
{
for ( yrs = 0;  yrs > 10;  yrs++ ) {
interest = amt * rt*yrs;
amt += interest;
System.out.println(interest);
}

}
}```
error message
pow(double,double) in java.lang.Math cannot be applied to (double)
finalInterest = amt* Math.pow((1 + rt)*yrs);
that's because the static method pow does not take one double, it takes two. Your code is passing in one double. look at the api:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html#pow(double,%20double)
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2007
Location
Chicago
Posts
4
Rep Power
0
Thanks

-michelle