The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Java compound interest
Discuss Java compound interest in the Java Help forum on Dev Shed. Java compound interest Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 20th, 2007, 10:17 PM
|
|
Registered User
|
|
Join Date: Mar 2007
Location: Chicago
Posts: 4
Time spent in forums: 1 h 4 m 53 sec
Reputation 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.
Thanks in advance
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);
|

May 20th, 2007, 10:31 PM
|
 |
Contributing User
|
|
Join Date: Oct 2003
Location: Wisconsin
|
|
Quote: | 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.
Thanks in advance
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)
|

May 20th, 2007, 10:58 PM
|
|
Registered User
|
|
Join Date: Mar 2007
Location: Chicago
Posts: 4
Time spent in forums: 1 h 4 m 53 sec
Reputation Power: 0
|
|
|
Thanks
-michelle
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|