Programming 1. Amortized Loan Calculator

The project is to create an amortized loan calculator program. An amortized loan is a loan that the borrower gradually pays down the loan in multiple fixed payments. Mortgage loans and auto loans are typically amortized loans.

An amortized loan is typically defined by its principle, interest rate, and term. The principle is the amount of money borrowed. The interest rate is often expressed in Annual Percentage Rate (APR), the interest rate for the whole year. The term is the length of the loan, typically in years.

If the interest is compound monthly, we can compute the monthly payment called the amortized monthly payment \(A\) as

\[A = P \frac{r (1 + r)^n} {(1 + r)^n - 1}\]

where \(P\) is the principle, \(r\) is the monthly interest rate, \(n\) is the term in months, i.e.,

\[r = \frac{APR}{12}\] \[n = 12 T\]

where \(T\) is the term of the loan in year.

Given the monthly payment \(A\), we can compute total payment \(S\) as

\[S = n A = 12 T A\]

and the total interest to be paid as

\[I = S - P\]

Requirement

You shall create a LoanCalculator class. The program shall read the principle (in whole dollar), the term (in whole years), and the APR from the standard input, compute the monthly payment, the total payment, and the total interest, and display the summary of the loan and the calculation. Your program’s output should be in the format exhibited in the example below,

$ java LoanCalculator
Amortized Loan Calculator v1.0
Enter the principle of the loan (in whole dollars, e.g., 1000): 200000
Enter the term of the loan (in years, e.g., 5): 15
Enter the annual interest rate (APR, e.g., 5.6): 6

          Summary of the Loan
          Principle: $200000
                APR: 6.0%
               Term: 15 years
    Monthly payment: $1687.71
      Total payment: $303788.46
     Total interest: $103788.46

It is important to note that all dollar amounts are displayed with two digits after the decimal points. For this, you are not supposed to use Math.round() function, instead, simply truncate the numbers to two digits after the decimal point.

In addition, the format must be exact; otherwise, CodeLab will reject the output.

Submission

Submit your work on https://codelab.turingscrat.com. Look for “Project 1” under “Programming Projects”.

Submission Deadline

The deadline is posted on the class Website.