The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Need Help Generating Loan Repayment Schedule

I'm supposed to get three inputs (loan amount, annual interest rate & loan period in years to repay loan) from the user and display a recommended repayment table based on the number of payments needed to pay back the loan... when i run the program it accepts the values but it only displays the payment for the first month and keeps reprinting those values.... is it a problem with my variables and data members or is something wrong with my methods?

Re: Need Help Generating Loan Repayment Schedule

thanks for the enlightenment i should change that and not make it a constant.... i thought i had to change the unpaid balance but how would i set the new unpaid balance every time without resetting my original loanAmount??? i tried to call the setAmount in the unpaidBalance method but that messed my results up so where should i get started on doing that?

(In the interest of full disclosure, I will admit that I just did the first two lines 'by hand' with a calculator. The others I got from a loan calculator on the web, and printed out values that your program should print. The point is that if the output of your program doesn't start and end like this, then there's more work to be done. I always make sure I have a test case with known output before I start writing a program to do the deed.)

Monthly payment doesn't change. It is calculated according to the initial balance and the APR and the number of payments. (By the way: Why didn't you initialize the balance in the constructor when you initialized the loan amount?) You recalculate the monthly payment every time you use it. Why? Why not make it a field of the class?

Anyhow:

Each month, the monthly interest amount is equal to current balance times monthly interest rate
Each month, the monthly principal amount is equal to monthly payment minus the monthly interest amount
Each month, balance is decreased by the amount of the monthly principal amount.

The question is: How is the balance decreased each month? In your unpaidBalance() method you calculate balance = loanAmount - principalPayment(), right? Why? loanAmount doesn't change. Shouldn't you be adjusting the balance by subtracting the principal payment from the previous balance?

Personally, I'm not too fond of using a method named unpaidBalance to adjust the balance. I would probably just have it return the balance and, perhaps make a separate method (makePayment() or some such thing) to adjust balance by subtracting current principal amount.) But the point is that calculations of interest are made on current balance, not original loan amount.

Re: Need Help Generating Loan Repayment Schedule

thanks for the help Z i finally got it working correctly!!! initializing the balance in the constructor helped alot... i changed unpaidBalance to void and made a get method to return the balance instead and made a couple of other changes as well.... all i needed was a little insight 'preciate it