Write the ccp program, which calculates and displays payments of a loan. The loa
ID: 3656011 • Letter: W
Question
Write the ccp program, which calculates and displays payments of a loan. The loan is a equal instalments loan, which means that that the Interest amount decreases as the principal amount gets lower. You may assume monthly payments and that the monthly interest persentage is equal to intersts for one year / 12. The list shall look as follows
You shall write this program in the following way:
1) Write a class called Loan.
2) The Loan class has no more than three member variables which are all
private: principal amount, annual interest rate and number of instalments (or
number of payments).
3) Write a. constructor) for the Loan.class.
4) The Loan:class shall have the following member functions:
a. The function computeInstalment() which returns the instalment. The function is
a private function.
b. The function computeBalance(int numPayment) which returns the balance
before payment number numPayment. The function is a private function.
c. The function computeInterest(int numPayment) which retunes the interest
amount of the payment number numPayment. The function is a private function.
d. The function displaySchedule() which prints the payment schedule. The
function is a public function.
Explanation / Answer
import java.io.*; import java.text.DecimalFormat; public class mortgagepaymentweek4 { public static void main(String[] args) throws IOException { int startNum, lineCtr, ctr, numMortgages; // initalize the year array. This will be a 3 index array with the // values // 7, 15, and 30 at indexes 0, 1, and 2 respectively int lastNum[] = { 7, 15, 30 }; int maxLineCtr = 25; double initAmt, begYearAmt, endYearAmt, intThisYear, cumInterest; // initialize the interest rates in the same manner as the years double intRate[] = { 0.0535, 0.055, 0.0575 }; String nothing; BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in)); DecimalFormat twoDigits = new DecimalFormat("0.00"); // grab the number of mortgages we are comparing, in this case 3 numMortgages = lastNum.length; lineCtr = 1; // start a for loop in order to loop through our array of mortgages for (int arrayIndex = 0; arrayIndexRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.