Results 1 to 12 of 12
Thread: Help with Equation
 09262013, 10:09 PM #1Member
 Join Date
 Sep 2013
 Posts
 9
 Rep Power
 0
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));
Last edited by TJRedeemer; 09272013 at 03:52 AM.
 09272013, 12:48 AM #2
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.
 09272013, 03:53 AM #3Member
 Join Date
 Sep 2013
 Posts
 9
 Rep Power
 0
Re: Help with Equation
Thanks for the warning, it's fixed.
 09272013, 04:10 AM #4
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; 09272013 at 04:12 AM.
If you don't understand my response, don't ignore it, ask a question.
 09272013, 04:11 AM #5Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 5,288
 Rep Power
 9
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,
JimLast edited by jim829; 09272013 at 04:43 AM.
The Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 09272013, 10:12 PM #6Member
 Join Date
 Sep 2013
 Posts
 9
 Rep Power
 0
Re: Help with Equation
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)); } }
 09272013, 10:31 PM #7
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.
 09272013, 10:54 PM #8Member
 Join Date
 Sep 2013
 Posts
 9
 Rep Power
 0
 09272013, 11:07 PM #9
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.
 09272013, 11:14 PM #10Member
 Join Date
 Sep 2013
 Posts
 9
 Rep Power
 0
 09272013, 11:38 PM #11Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 5,288
 Rep Power
 9
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,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 09282013, 12:10 AM #12Member
 Join Date
 Sep 2013
 Posts
 9
 Rep Power
 0
Similar Threads

Quadratic equation help please.
By proPAGANda in forum New To JavaReplies: 3Last Post: 10092012, 01:36 PM 
Looking for explanation of equation
By flyersjoe in forum New To JavaReplies: 9Last Post: 09132011, 05:08 AM 
Help with equation
By _Jk_ in forum New To JavaReplies: 10Last Post: 03172011, 09:15 PM 
equation
By bobo67 in forum New To JavaReplies: 5Last Post: 09062010, 06:40 PM 
Need help with math equation
By annabellastorm in forum New To JavaReplies: 4Last Post: 01102010, 06:12 PM
Bookmarks