Calculating Monthly Payments

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 annual rate is 6%, for example, c = 0.06 / 12 = 0.005.)

$$P = L \cdot \frac{c(1+c)^n}{(1+c)^n - 1}$$

Write an class named MonthlyPaymentCalculator whose main method calculates such a monthly payment (to the nearest cent), after prompting the user to enter the loan amount, the annual interest rate, and the term of the loan (in years).

Sample run:

This program calculates the fixed monthly payment to fully amortize a loan
Enter the loan amount in dollars: 185000
Enter the annual interest rate (e.g., for 6%, enter 0.06): 0.035
Enter the term of the loan in years: 30
The fixed monthly payment for this loan will be $830.73.
The amount spent to pay off this loan over its entire term is $299063.76.

Tags: java.util.Scanner, printf(), Math.pow()