Mortgage Calculator W/ Gui (wk 4)
Essay by review • February 4, 2011 • Essay • 461 Words (2 Pages) • 1,291 Views
Filename: MortCalc.java
/*
Version: 1.0 - Initial version
2.0 - Modified the mortgage program from Week 2 to add a list of the loan
balance and interest paid for each payment over the term of the loan
(amortization table). Added loops and pauses for legibility purposes.
2.1 - Broke calculations down into three different methods for assignment
requirements.
3.0 - Modified the mortgage program from version 1.0 to display 3 mortgage
loans. Included all mortgage functionality in one class and created a
separate class that instantiates the first and displays the mortgage
payment amount for each loan. Removed amortization table function.
4.0 - Add a GUI interface and loop and remove the preset loan values.
5.0 - Create buttons for 3 preset loan rates & terms. Also changed interface
to a set size to increase visual appeal and user-friendliness. Added an
amortization table to display loan & interest paid amounts for every payment.
6.0 - Combine the previous two versions: an option to enter custom loan variables
as well as the 3 preset options.
7.0 - Modified the program to read the preset mortgage rates from a file, and
added a chart.
Purpose: Calculate the monthly payment amount for a mortgage loan using a GUI interface.
*/
import java.text.*;
import java.math.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MortCalc
{
public static void main (String[] args)
{
JFrame window = new MortCalcGUI();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
}
class MortCalcGUI extends JFrame implements ActionListener
{
/*declare GUI function variables*/
protected JButton bCalc7, bCalc15, bCalc30, bCustom, bClear, bExit;
protected JLabel labelPayment, labelLoanAmount, labelTitle, labelInstructions,
labelAmortTable, labelAPR, labelTerm, labelOr, labelThen;
protected JTextField fieldPayment, fieldLoanAmount, fieldTerm, fieldAPR;
protected JTextArea areaAmortTable;
/*Copy the data from the "loanArray" method to an array named "loan" to save recoding time*/
double loan [][] = loanArray();
/*Gather loan information from file*/
public double [] [] loanArray ()
{
/*Initialize array to load data from parsing the file*/
double array[] = new double[6];
try
{
int index = 0;
BufferedReader fileIn = new BufferedReader(new FileReader("Values.txt"));
String temp = null;
Double value = 0.0;
while((temp = fileIn.readLine()) != null)
{
/*convert the string to a double for calculation purposes*/
try
{
value = Double.parseDouble (temp);
}
...
...