Piet Souris wrote:hi Johnny,
welcome to the Ranch!
The final payment will be at most the monthly payment. For instance, say the monthly payment = 50 (MP), the interest rate (IR) = 0.02, and the balance one payment period before the end = 40.
The interest paid (IP) is indeed balance * IR = 40 * 0.02 = 0.80. The principalPaid (PP) is first MP - IP = 50 - 0.80 = 49.20.
Since now the PP > balance, we must limit the PP to that balance. That means that PP will become equal to the balance (40), and the monthly payment for that final month will be equal to PP + IP.
So, what check do you have to do in your for loop, and what adjustments are eventually needed?
Again, welcome to the Ranch
Johnny Doey wrote:I'm new to java
That is not the correct way to calculate amortisation. There is a simple formula which I can't remember, but you can doubtless find easily enough.
and creating a simple loan amortization table.
You use the nominal interest rate, not the APR.
The user inputs loan amount, APR, and monthly payment. You are not asking for APR anyway.
There are all sorts of style issues about that code:-
I'm 99% done but I realized the program subtracts the final payment (even if it's less than the loan balance remaining). Here is the code in question:
. . .
Piet Souris wrote:Okay.
Your for loop starts as follows:
Now, here you could check the principalPaid, like:
I thought nominal interest was the correct thing to use. But be sure to make your user prompts clear and unambiguous. You cannot divide APR by twelve and get the monthly interest. You do that to the nominal rate. If you want to convert APR to monthly rate you would have to take the twelfth root of something.
Johnny Doey wrote:. . . I'm using nominal interest rate in my formulas but I was referencing what the user inputs, which is APR
That isn't called interest paid; it is called interest receivable (at least on this side of the Pond) or interest due. Make sure the variable name reflects what it means.
The interestPaid I'm using calculates how much interest is due each month . . .
These rules may vary from country to country. As I said, you take the nominal annual rate and divide it by twelve.
Piet Souris wrote:I have to disagree slightly.
It is very common to calculate the montly interest rate by dividing the yearly rate by 12.
This may vary from country to country but APR is what you call the real rate. As you said, you would never use that to calculate interest due; the APR can be calculated from monthly interest to the 12th power.
Only for theoretical interest calculations one calculates the monthly interest rate by taking the 12th root. There is indeed a difference between the 'real yearly interest rate' and the 'apparent yearly interest rate'.
In which case the name balance is also wrong. Once the interest has been paid, the interest due drops to 0 until the next month.
And as for the naming: just before the client pays his monthly payment, he is indeed interest due, and the interest is receivable. But dt seconds after payment, the client has 'interest paid', and his 'balance', as OP names it, has decreased.