Results 1 to 12 of 12
  1. #1
    TJRedeemer is offline Member
    Join Date
    Sep 2013
    Posts
    9
    Rep Power
    0

    Default Help with Equation

    I'm working on an assignment for school. The assignment is right here:

    CP 1 - Assignment # 2

    And before you ask, no I am not asking anyone to do my work for me, I'm just asking for help. You see, when I run the first test, I get $600000.00 instead of $599.55, which is apparently what I am supposed to get. The proper equation is shown on the webpage, but I can't seem to figure out what is wrong with mine. Can anyone help? The code is attached.

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package loanpaymentfinder;
    
    import java.text.NumberFormat;
    import java.util.Scanner;
    
    /**
     *
     * @author TJ
     */
    public class LoanPaymentFinder {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            
            Scanner in = new Scanner(System.in);
            
            NumberFormat num = NumberFormat.getCurrencyInstance(); 
            
            double numInputLoan;
            double numInputRate;
            double numInputYears;
            double numMonths;
            double numRateSquared;
            double numOutput;
            double numRatePlusOne;
            
            //Input
            System.out.print ("Enter loan amount: ");
            numInputLoan = Double.parseDouble (in.nextLine());
            
            System.out.print ("Enter rate: ");
            numInputRate = Double.parseDouble (in.nextLine());
            
            System.out.print ("Enter number of years: ");
            numInputYears = Double.parseDouble (in.nextLine());
            
            //Math goes her
            
            numMonths = 12 * numInputYears;
            
            numRatePlusOne = numInputRate + 1;
            
            numRateSquared = Math.pow (numRatePlusOne, numMonths);
            
            numOutput = numRateSquared/(numRateSquared - 1);
            
            numOutput = numInputRate * numInputLoan * numOutput;
            
            //Output
            System.out.println ("The mounthly payment is:");
            System.out.println (num.format(numOutput));
    Attached Files Attached Files
    Last edited by TJRedeemer; 09-27-2013 at 03:52 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,411
    Rep Power
    25

    Default Re: Help with Equation

    Please post the code on the forum. Be sure to wrap the code with code tags.
    [code]
    >>>>>>>COde HErE
    [/code]
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    TJRedeemer is offline Member
    Join Date
    Sep 2013
    Posts
    9
    Rep Power
    0

    Default Re: Help with Equation

    Thanks for the warning, it's fixed.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,411
    Rep Power
    25

    Default Re: Help with Equation

    There are an number of statements used to compute the value that is printed. Have you verified that each one is generating the correct result? Add a println statement after each one that prints out the results so you can see which statements are not doing what you want.

    Also you need to post what the user inputs to the program when it is executed. Three values are read in. What are they?
    Last edited by Norm; 09-27-2013 at 04:12 AM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,610
    Rep Power
    5

    Default Re: Help with Equation

    The problem is with your interest rate. You enter it as a whole number. But it is supposed to be a percentage. That means it needs to be divided by 100.
    However, since you are amortizing your load amount monthly and the entered interest rate is annual, you need to divide again by 12. So in total, your entered interest rate needs to be divided by 1200.

    Regards,
    Jim
    Last edited by jim829; 09-27-2013 at 04:43 AM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    TJRedeemer is offline Member
    Join Date
    Sep 2013
    Posts
    9
    Rep Power
    0

    Default Re: Help with Equation

    Quote Originally Posted by jim829 View Post
    The problem is with your interest rate. You enter it as a whole number. But it is supposed to be a percentage. That means it needs to be divided by 100.
    However, since you are amortizing your load amount monthly and the entered interest rate is annual, you need to divide again by 12. So in total, your entered interest rate needs to be divided by 1200.

    Regards,
    Jim
    Thanks, I've almost got it, but now it gives me $500. I can't see what else is wrong here. Can someone help me?

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package loanpaymentfinder;
    
    import java.text.NumberFormat;
    import java.util.Scanner;
    
    /**
     *
     * @author TJ
     */
    public class LoanPaymentFinder {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            
            Scanner in = new Scanner(System.in);
            
            NumberFormat num = NumberFormat.getCurrencyInstance(); 
            
            double numInputLoan;
            double numInputRate;
            double numInputYears;
            double numMonths;
            double numRateSquared;
            double numOutput;
            double numRate;
            
            //Input
            System.out.print ("Enter loan amount: ");
            numInputLoan = Double.parseDouble (in.nextLine());
            
            System.out.print ("Enter rate: ");
            numInputRate = Double.parseDouble (in.nextLine());
            
            System.out.print ("Enter number of years: ");
            numInputYears = Double.parseDouble (in.nextLine());
            
            //Math goes here
            
            numMonths = 12 * numInputYears;
            
            numInputRate = numInputRate / 1200;
            
            numRateSquared = numInputRate + 1;
            
            numRateSquared = Math.pow (numRateSquared, numMonths);
            
            numOutput = numInputRate * numInputLoan * numRateSquared/numRateSquared * -1;
            
            //Output
            System.out.println ("The mounthly payment is:");
            System.out.println (num.format(numOutput));
            
            
            
        }
    }

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,411
    Rep Power
    25

    Default Re: Help with Equation

    Have you looked at the results of each statement to see where the code is going wrong?
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    TJRedeemer is offline Member
    Join Date
    Sep 2013
    Posts
    9
    Rep Power
    0

    Default Re: Help with Equation

    Quote Originally Posted by Norm View Post
    Have you looked at the results of each statement to see where the code is going wrong?
    Yes, and it seems like the problem is with Math.pow method. The equation should be like (1+Rate)^months, but when the rate is 6%, it gives me $6.02, which is obviously wrong.

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,411
    Rep Power
    25

    Default Re: Help with Equation

    Can you post statement, the values of the variables used in that statement and the results of executing the statement that shows what you are talking about. Also post what you expect the output to be.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    TJRedeemer is offline Member
    Join Date
    Sep 2013
    Posts
    9
    Rep Power
    0

    Default Re: Help with Equation

    Quote Originally Posted by Norm View Post
    Can you post statement, the values of the variables used in that statement and the results of executing the statement that shows what you are talking about. Also post what you expect the output to be.
    numRateSquared = Math.pow (numRateSquared, numMonths); The statement should be $599.55.

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,610
    Rep Power
    5

    Default Re: Help with Equation

    How can you almost have it? You should totally have it!! Take your original code (First post), add a closing brace, and simply divide the input rate by 1200.
    Do not change anything else.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  12. #12
    TJRedeemer is offline Member
    Join Date
    Sep 2013
    Posts
    9
    Rep Power
    0

Similar Threads

  1. Quadratic equation help please.
    By proPAGANda in forum New To Java
    Replies: 3
    Last Post: 10-09-2012, 01:36 PM
  2. Looking for explanation of equation
    By flyersjoe in forum New To Java
    Replies: 9
    Last Post: 09-13-2011, 05:08 AM
  3. Help with equation
    By _Jk_ in forum New To Java
    Replies: 10
    Last Post: 03-17-2011, 08:15 PM
  4. equation
    By bobo67 in forum New To Java
    Replies: 5
    Last Post: 09-06-2010, 06:40 PM
  5. Need help with math equation
    By annabellastorm in forum New To Java
    Replies: 4
    Last Post: 01-10-2010, 05:12 PM

Posting Permissions

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