# Programming questions 2

Program Specifications: Congratulations! The “Mafiosa Bank of Uncle Sal” in Miami has accepted your application for a 20 year mortgage on your first home. You put $25,000 down on a $325K house and will be borrowing $300K (three hundred thousand) from the bank at an interest rate of 4.25%. The terms of the loan state that you only make one payment per year to the bank in December for an agreed upon amount. For the very last payment (year 20), you must pay the entire remaining amount due. You now realize this is not such a great deal, but you have signed the contract and until a lawyer gets you out of it, you are stuck.

So at the end of every calendar year, several things take place:

- The bank computes the interest based on what you currently owe.
- The bank adds the interest to the amount due resulting in the revised amount due.
- You make your agreed upon payment which reduces the total amount you owe.

Note: Yes, the bank computes the interest and adjusts the total amount owed *before* you make your payment (you know why don’t you?).

In gathering information for your lawyer, you want to demonstrate how much you will have to pay at the end of your loan period of 20 years. To do this, you have to write a program that will read a variable “amount” from the keyboard that will be the agreed upon amount to pay yearly to the bank. Your program will then print the results of the calculations for each year as follows:

Example of input/output (you must have the same wording – only the amounts will change depending upon the payment):

Annual amount ($) ? 10000

At the end of year 1 Remaining due: 302750 Total interest: 12750 Total paid: 10000

At the end of year 2 Remaining due: 305616 Total interest: 25616 Total paid: 20000

At the end of year 3 Remaining due: etc.

…etc.

At the end of year 19 Remaining due: 377982 Total interest: 267982 Total paid: 190000

At the end of year 20 Remaining due: 394046 Total interest: 284046 Total paid: 584046

Program Requirements:

- Alignment – You do not have to have the output aligned exactly as above. It should simply be neat and easy to read. You must use the exact same wording as above.
- Constants – Your program must define the rate, duration of loan, and amount borrowed as class constants.
- Numeric Types – The calculations should be made with variable of an appropriate type – but you should output only dollars. Use casting to do that (there are ways to print double with appropriate number of decimals – we will see that later).
- Valid Data – You can assume the amount entered is a positive real number less than 23000.
- Style – Be sure to follow the guidelines of good style using proper indentation, well-chosen identifiers and appropriate use of comments.

TIPS:

- Setting up your loop – In general with loops, the tricky part is the start of the loop and the end of the loop. Here obviously the result of the year 20 is *special* since the calculation is not the same as for other years. Because of this, you may want to loop for only 19 years and do the last year outside of the loop.
- Testing your program – Submitting a program that has no syntax errors is not good enough for a perfect score. You need to start testing your programs for errors. Think of all cases where it is relatively easy to check if your program works properly. F for example:
- What happens if the agreed upon amount to pay yearly is zero dollars?
- What happens if the amount paid yearly is one dollar? A hundred dollars? Ten-thousand dollars?