Lab #9: GUI Loan Calculator

Background: Read this, then follow the steps below

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:


NOTE: You are to use good object oriented design practices in creating this program!

Step 1: The shell of a GUI (40pts)

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.

GUI Rules:

  1. Your GUI window must mimic the example above with the exception of the placement for the various items. However, the labels for the items must remain adjacent to their respective JTextField or JComboBox.
  2. The window must have a title in the format: Last, First - alphacode

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 (15pts)

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. "$234.35" not "$234.34897103". There's a nice Math.round() method that can help you do this.

Caution: It is possible for a montly payment to be so low that it is impossible to pay off the loan. Your program must check for this occurence and perform appropriate error handling.

Remember: Use good OOP practices!

Although there is not a specified input/output behavior, here are a few example 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 (35pts)

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, tie together your code from Steps 1 and 2.

Remember: Use good OOP practices!

Javadoc and Coding Style (10pts)

You commented every file, every class, every method, right?

Submitting the lab

  1. There are no automated tests for this lab, but you'll submit it online as usual.
  2. Make sure all your .java files are commented according to the course standard for generating Javadoc.
  3. cd to the directory that contains your lab files, and give this command:
    ~/bin/submit -c=IC211 -p=Lab09 *.java