![]() |
|
|
#1 | ||
|
Coordinator
Join Date: May 2003
Location: Utah
|
Java help - I don't think this is right...
Alright, I am in a Java class right now, and for homework, I have to build a mortgage application, and I have the Principal, Annual Rate, and Length hard coded in (part of the assignment)
Then, based off of that, I am to figure out the monthly payment. Code:
running the formula of Monthly Payment = Principal * (Monthly Interest / (1 - (1 + Monthly Interest) * -Number of Months) The number does not a appear to be correct to me... However, I can not see what I am doing wrong, can anyone look at it and see if they can point out what I am doing wrong...
__________________
"forgetting what is in the past, I strive for the future" |
||
|
|
|
|
|
#2 |
|
Registered User
Join Date: Nov 2001
Location: Here
|
This is probably horribly wrong, but try this:
dpayment = (iAmount+(iAmount*dMonthRate)/iMonthsTotal)) Doubt this is right, but it gives a number that looks reasonably normal. |
|
|
|
|
|
#3 |
|
Coordinator
Join Date: May 2003
Location: Utah
|
I tried that, but the monthly payment was like 20K it appeared to me.
__________________
"forgetting what is in the past, I strive for the future" |
|
|
|
|
|
#4 |
|
College Prospect
Join Date: Oct 2000
Location: Baltimore, MD
|
payment = (initAmount / (1- ((1 + monIntRate)^-nMonths)))
is that right? |
|
|
|
|
|
#5 | |
|
Coordinator
Join Date: May 2003
Location: Utah
|
Quote:
This has provided the closest result so far...I guess the instructor might have to let me know if I am wrong or right.
__________________
"forgetting what is in the past, I strive for the future" |
|
|
|
|
|
|
#6 |
|
Head Coach
Join Date: Jul 2001
|
http://www.mtgprofessor.com/formulas.htm
The following formula is used to calculate the fixed monthly payment (P) required to fully amortize a loan of L dollars over a term of n months at a monthly interest rate of c. [If the quoted rate is 6%, for example, c is .06/12 or .005]. P = L[c(1 + c)^n]/[(1 + c)^n - 1] |
|
|
|
|
|
#7 |
|
Head Coach
Join Date: Jul 2001
|
so I think: P = L[c(1 + c)^n]/[(1 + c)^n - 1]
is: dPayment = iAmount * ( (dMonthRate * Math.pow((1+dMonthRate),iMonthsTotal)) / (Math.pow((1+dMonthRate),iMonthsTotal) - 1) ); ... I think, I didn't actually try it out. Parentheses may need adjusting and there may be some casting required. |
|
|
|
|
|
#8 | |
|
Coordinator
Join Date: May 2003
Location: Utah
|
Quote:
This works, a lot better than what I had...Thank you so much for your assistance
__________________
"forgetting what is in the past, I strive for the future" |
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|