Results 1 to 4 of 4
  1. #1
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Exclamation beginner grade 11-need help with a math code involving returning values from a method

    My following code is to calculate the monthly payment of someones mortgage. I was given the formula:
    payment = loan * (rate/100/12) / ( 1 - ( 1 / ( 1 + (rate/100/12) )) ^ (years * 12 ))

    How can I substitute the '^' with Math.pow in order to get this equation to work in my code.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Java Code:
        public static double pow(double a, double b) {
    	return StrictMath.pow(a, b); // default impl. delegates to StrictMath
        }
    There are special casing issues for various situations, this should get you unstuck...
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    bobmasta5 is offline Member
    Join Date
    Dec 2008
    Location
    North America
    Posts
    29
    Rep Power
    0

    Default

    Im not really sure how to do it still. Its my first year programming and Math.pow is suppose to replace the '^' somehow without nothing to technical.

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    you have to sit there and pencil and paper your way through it...

    double years = ?....
    double twelve = new Double(12.0000);

    ( rate divided by 100 divided by 12 )

    divided by .... start with the innermost round braces and work your way out, keep careful detail on exactly when each round brace closes, it is programmed by carefully working that one pair at a time:

    one plus (rate/100/12) then one is divided by that number then.....

    tedious, error-prone, yes.

    do homework, no.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. Replies: 11
    Last Post: 12-08-2008, 01:29 AM
  2. Need help. Method won't returning proper value..
    By zlwilly in forum New To Java
    Replies: 2
    Last Post: 12-02-2008, 10:44 PM
  3. Simple program involving military time
    By busdude in forum New To Java
    Replies: 4
    Last Post: 10-08-2008, 07:03 PM
  4. Replies: 13
    Last Post: 07-06-2008, 10:11 AM
  5. Replies: 0
    Last Post: 12-01-2007, 12:55 AM

Posting Permissions

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