## First 1/2 hour: The 12-week exam Object Oriented Design mini-Practicum

For this lab you will write a program that provides a simple loan calculator with a GUI interface. Here's an example of what it might look like:

The idea here is that "loan amount", "rate" and "monthly payment" are inputs. The user enters or chooses values for them, then presses the calculate button, which causes the program to calculate values for "months to payoff" and "cost" and display them in the GUI.

The financial rules for this are simple:

1. At the end of each month, you accrue interest according to the formula interest = balance*rate/1200, where "rate" is assumed to be in percentage form, e.g. "5.25%".
2. At the end of each month, after the interest is accrued, the monthly payment is made.
3. At the end of each month, after the interest is accrued and the monthly payment is made, if the balance is less than or equal to zero, the loan is considered to be "paid off", and any overpayment (the amount by which the balance is in the negatives) is repaid to the borrower.
4. The "cost" of the loan is given by the formula: cost = total amount paid - amount of overpayment repaid - original loan amount.

Here are a few examples:
• if amount = \$100.00, rate=5%, monthly payment = \$200.00, then after one month we accrue \$0.42 in interest. This leaves a new balance of \$100.42. The payment is \$200, leaving a balance of -99.58. So \$99.58 gets repaid, and the simulation is over. It lasted 1 month, and the cost was 200 - 99.58 - 100.0 = \$0.42.
• if amount = \$500.00, rate=6.75%, monthly payment = \$40.00, then months = 13 and cost is \$19.91.
NOTE: You are to use good object oriented design practices in creating this program!

## Step 1: The shell of a GUI

Write the code that creates the window with the GUI components, but without the code that reacts to the button push or does any of the financial calculations. Your interface should support interest rates from 3.5 to 7.5 in increments of 0.25.
Note: Don't worry about getting the layout perfect at this point. Just get the components on the screen, After everything else is working you can go back and play with the layout to your heart's content without breaking anything else.

## Step 2: The financial stuff

Write the code to do the financial computations. Write it completely separately from the GUI - you should be able to run and test it from the command line, and its class/classes should have nice interfaces (i.e. public methods) for providing inputs and requesting outputs. Once again, at this point the financial calculation code should have no connection to the GUI code. Note that the number of months should be an integer value, and the "cost" should be rounded appropriately, i.e. I want "234.35" not "234.34897103". There's a nice Math.round() method that can help you do this.

Remember: Use good OOP practices!

Although I'm not specifying input/output behavior for whatever you do, here are a few runs of my program to give you some values to test:

```~/\$ java Calc
usage: java Calc <amount> <rate> <payment>
~/\$ java Calc 4500.00 4.25 95.50
months = 52  cost = 432.06
~/\$ java Calc 4500.00 7.25 95.50
months = 56  cost = 811.89
~/\$ java Calc 4500.00 7.25 85.50
months = 64  cost = 932.27```

## Step 3: Putting them together

Now write the code to react to a button push by doing the financial calculations and displaying the output results in the GUI. In other words, now tie together your code from Steps 1 and 2.
Remember: Use good OOP practices!