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:
interest = balance*rate/1200
, where "rate" is assumed to be in percentage form, e.g. "5.25%".
cost = total amount paid - amount of overpayment repaid - original loan amount
.
Here are a few examples:
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:
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.
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
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!
You commented every file, every class, every method, right?
~/bin/submit -c=IC211 -p=Lab09 *.java