2 Replies - 762 Views - Last Post: 01 December 2010 - 02:10 PM Rate Topic: -----

#1 lldillon2004   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-December 10

Mortgage Calculator

Posted 01 December 2010 - 11:54 AM

Hello
I am trying to develop java code that displays the principle balance, interest paid over the term of the loan. Without a GUI. The principle loan amount is 200,000.00 with an interest rate of .0575 on a 30year term loan.
I have successfully computed the payment amount of 1167.15

Now with this information I must develop a loop that will reduce the principle by whatever is left over after paying that months interest. The following is the code doing this:

double interestPaid = loanBalance * interest/12;
double principlePayment = monthlyPayment-interestPaid;
double loanBalance = P-principlePayment;

My question is How does the computer know to replace the loanBalance, with the "new" loanBalance after a payment is applied?

I have tried to use the term in months "360" as a counter for the loop but I get a "reached end of file while parsing" when I attempt this.
Any ideas on how I can correct my code to achieve a working Mortgage Calculator?

Is This A Good Question/Topic? 0
  • +

Replies To: Mortgage Calculator

#2 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

Re: Mortgage Calculator

Posted 01 December 2010 - 01:56 PM

"reached end of file while parsing" is an error that occurs when you have too little ending braces. These: }

Go through your program and indent it correctly. When you do this, you will notice that a } is missing somewhere. If you put it in, you will fix this issue. If you need further help please :code: so that we can further help you.
Was This Post Helpful? 0
  • +
  • -

#3 midhir   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 27-October 10

Re: Mortgage Calculator

Posted 01 December 2010 - 02:10 PM

Heh I just finished that class about a week ago as for the question: Without being able to see all your code makes it harder to answer so I will best guess it.

Quote

How does the computer know to replace the loanBalance, with the "new" loanBalance after a payment is applied?


During the loop to display the information I am assuming P = 200000.00

double loanBalance = P - principlePayment



should actually not include the orginal variable for the primary loan amount because it is a constant, new need to use a variable like newLoanAmount and define it as a double where you are defining all your variables Here is an example:

newLoanAmount = newLoanAmount - monthlyCost;  //Redefine value for newLoanAmount



Quote

I have tried to use the term in months "360" as a counter for the loop


Use the newLoanAmount as your counter for that loop and loop until until it equals 0.

while (newLoanAmount01 > 0) {
       newLoanAmount01 = newLoanAmount01 - monthlyCost01;



Hope this helps
Mike

ps: do a search on this site for "Java Mortgage Calculator" and you will find lots of code that will help.

This post has been edited by midhir: 01 December 2010 - 02:14 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1