Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 20th, 2007, 10:17 PM
mic822 mic822 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Location: Chicago
Posts: 4 mic822 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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);

Reply With Quote
  #2  
Old May 20th, 2007, 10:31 PM
nizack05's Avatar
nizack05 nizack05 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wisconsin
Posts: 134 nizack05 User rank is Sergeant Major (2000 - 5000 Reputation Level)nizack05 User rank is Sergeant Major (2000 - 5000 Reputation Level)nizack05 User rank is Sergeant Major (2000 - 5000 Reputation Level)nizack05 User rank is Sergeant Major (2000 - 5000 Reputation Level)nizack05 User rank is Sergeant Major (2000 - 5000 Reputation Level)nizack05 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 8 h 30 m 33 sec
Reputation Power: 44
Send a message via AIM to nizack05
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)

Reply With Quote
  #3  
Old May 20th, 2007, 10:58 PM
mic822 mic822 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Location: Chicago
Posts: 4 mic822 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 53 sec
Reputation Power: 0
Thanks

-michelle

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Java compound interest

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap