• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Loan payment calculator

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my code. I don't know what I should put in the while loop and I'm stuck at the second method, which is the pay off loan.

 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Do you mean the do/while loop?  Right now it loops forever; probably not a good idea.  How about asking if they user wants to calculate another loan and in the while, test for yes/no?

What are you stuck on?  Please TellTheDetails (that's a link).
 
Marshal
Posts: 80227
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and welcome to the Ranch
 
Thanh Hoang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I want my program determine how many months it will take to pay off that loan, what the final payment amount will be, and how much interest was paid over that time. If the monthly payment amount isn't high enough to pay off more than one month's interest, my program should notify the user what the minimum monthly payment is
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you weren't given these formulae?  Does this help?

https://en.wikipedia.org/wiki/Amortization_calculator
 
Thanh Hoang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry but no, It doesn't help anyway. I'm stuck on the formular to calculate the interest month and count how many month did we use to paid off.
Like this example
How much do you want to borrow? $1000
What is the annual interest rate expressed as a percent? 18
What is the monthly payment amount? $50
Your debt will be paid off after 24 months, with a final payment of just $47.83
The total amount of interest you will pay during that time is $197.83
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this help?

https://en.wikipedia.org/wiki/Amortization_schedule#Outstanding_loan_balance_calculation

(I'm just Googling this stuff.  The keyword is "amortization".  So this link was found with amortization number of payments)
 
Thanh Hoang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my code so far. And I still don't understand about the interest month. If you can give me a hint or a code, It will be my pleasure.

 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please surround your code with code tags.  Please read this.
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I still don't understand about the interest month. If you can give me a hint or a code...


I believe I've given you the information you need.  If you have a specific question, I'll be glad to answer it.  If you're looking for me or anyone to supply you with the code, that's not going to happen.  CodeRanch is not a code mill.
 
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this reply: click here
I tried to give a hopefully comprehensible explanation regarding some elementary financial maths formulae.

Let the monthly payment be P, and let the monthly interest be rr (per unit loan, for instance 0.005). Since we do not want the unamortized part of the loan to increase each month, we need to make P at least equal to the monthly interet payment. So we get, the loan being L:

1) P >= rr * L (if P = rr * L, we call this a perpetuity,  a never ending loan)

2) let the unamortized Loan at the end of month m, right after the monthly payment, be UL(m). We get this recursion relation (can you think of why?)

  UL(m + 1) = UL(m) * (1 + rr) - P

3) and of course, UL(0) = L

Now, at the end of each month m, just before the payment P, the UL is equal to UL(m) * (1 + rr). To determine both the duration and the final payment, we get this while loop:



Note: I typed this code straight from  the keyboard, and so is untested.

HTH,
Piet

edit: reversed the lines of interestTotl and UL
 
Thanh Hoang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will run to infinity This is my code so far.

Can we count the number on the new balance as the number of month?
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanh Hoang wrote:It will run to infinity


Not when I run my code.

Thanh Hoang wrote:Can we count the number on the new balance as the number of month?


Well, test it, but what 'number on the new balance' are you referrng to?

Anyway, I ran your latest code, together with my code. This is what I got:

** Welcome to the Consumer Loan Calculator **
How much do you want to borrow? $100
What is the annual interst rate expressed as a percent? 12
What is the monthly payment amount? $4
Your dept will be paid off after months97.0
with a final payment of just $101.0
The total amount of interest you
will pay during that time is $1.0
************************************
loan is amortized after 29 months.
with a final payment of  3,65
total interest paid = 15,65
*******************************************

So there is still some work to be done. See if you can spot why you got an infinite run time with my code, it means giving the code some thorough testing!
 
Campbell Ritchie
Marshal
Posts: 80227
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Please surround your code with code tags.  . . .

I corrected that bit, and doesn't it look better Your code tags shou‍ld look like this:-
[code=java]
if (tagsOK)
{
    System.out.println("Code tags OK");
}
[/code]

...and welcome to the Ranch
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic