Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By raZieL777

Thread: Getting an Error!

  1. #1
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default Getting an Error!

    I am not exactly sure whats the case is but I am getting a syntax sort of error:

    temp = (1.0/(pow(x,y)));
    ^
    in this line

    Java Code:
    import java.util.Scanner;
    import java.text.DecimalFormat;
    import java.lang.Math;
    
    public class Finance {
      
     public static void main(String[] args) {
      
      Scanner input = new Scanner(System.in);
      
      System.out.print("Principal Amount: ");
      double Principal_Amount = input.nextDouble();
      
      System.out.print("Term of Mortgage in Years: ");
      double Term_Mortgage = input.nextDouble();
      
      System.out.print("Interest Rate: ");
      double Interest = input.nextDouble();
      
        double payment, r, temp, x, y, future_value, interest_charged;
        r = Interest/100.0;
        x = 1.0+r/12.0;
        y = Term_Mortgage * 12.0;
        temp = (1.0/(pow(x,y)));
        payment = (Principal_Amount*r/12.0)/(1-temp);
        future_value = payment * Term_Mortgage * 12.0;
        
        interest_charged = future_value - Principal_Amount;
    
    
        System.out.println("Principal: $" + Principal_Amount);
        System.out.println("Future Value: $"+future_value);
        System.out.println("Terms of Loans in Years :" +Term_Mortgage);
        System.out.println("Interest Rate :" +Interest);
        System.out.println("Interest Charged :" +interest_charged);
        System.out.println("Payment: "+payment);
        
      }
    }
    Thanks
    Last edited by racewithferrari; 09-08-2012 at 07:30 AM. Reason: formatting

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default Re: Getting an Error!

    Post what is the syntax error?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Getting an Error!

    Learn to follow the Java coding conventions. Variable names start with a lowercase letter.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Join Date
    Sep 2012
    Location
    Bangalore,India
    Posts
    1
    Rep Power
    0

    Default Re: Getting an Error!

    problem:The method pow(double,double) is undefined for the type Finance
    solution:To fix this you have to create method 'pow(double,double)'
    Try this code below best of luck dear

    import java.util.Scanner;
    import java.text.DecimalFormat;
    import java.lang.Math;

    public class Finance {

    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    System.out.print("Principal Amount: ");
    double Principal_Amount = input.nextDouble();

    System.out.print("Term of Mortgage in Years: ");
    double Term_Mortgage = input.nextDouble();

    System.out.print("Interest Rate: ");
    double Interest = input.nextDouble();

    double payment, r, temp, x, y, future_value, interest_charged;
    r = Interest/100.0;
    x = 1.0+r/12.0;
    y = Term_Mortgage * 12.0;
    temp = (1.0/(pow(x,y)));
    payment = (Principal_Amount*r/12.0)/(1-temp);
    future_value = payment * Term_Mortgage * 12.0;

    interest_charged = future_value - Principal_Amount;


    System.out.println("Principal: $" + Principal_Amount);
    System.out.println("Future Value: $"+future_value);
    System.out.println("Terms of Loans in Years :" +Term_Mortgage);
    System.out.println("Interest Rate :" +Interest);
    System.out.println("Interest Charged :" +interest_charged);
    System.out.println("Payment: "+payment);

    }

    private static double pow(double x, double y) {
    return 0;
    }
    }

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Getting an Error!

    BB Code List - Java Programming Forum

    Try this code below
    Don't spoonfeed. That denies the questioner of a learning opportunity and is not considered helpful.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    raZieL777 is offline Member
    Join Date
    Jun 2012
    Location
    Austria
    Posts
    1
    Rep Power
    0

    Default Re: Getting an Error!

    Hey,

    your problem is that your class Finance doesn't have a method called pow.
    I see that you imported the Math class. That's good. It means that you know, that the pow method is in that class.

    Now - your mistake here is that you need Java to tell, which pow method to call. Since the pow method within the Math-class is static (see the API: Math (Java Platform SE 6)) you have to call it statically.
    Classes are not really like libraries in C or C++ for instance. You can't just import one and then access it's methods. You either have to instantiate a class (i.e. by calling new) - or, if applicable - call the desired method statically.

    Hope this helps, don't want to just give you the example, since that would rob you of a (great) "aha"-moment.
    PhQ likes this.

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2012, 05:26 PM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •