Prg 421 Week 2 Program - Change Request #4

Only available on StudyMode
  • Download(s) : 40
  • Published : March 19, 2012
Open Document
Text Preview

Change request 4 - week 2 Assignment
Requestor: Ninfa Pendleton - Rapid City, SD
Description: Write the program in Java (with a graphical user interface) and have it
calculate and display the mortgage payment amount from user input of the amount
of the mortgage, the term of the mortgage, and the interest rate of the mortgage.
Allow the user to loop back and enter new data or quit.
Please insert comments in the program to document the program. Version: 2.0.1


import java.text.DecimalFormat;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
import java.applet.Applet;
import java.util.*;

public class WK2MortCalcVer_2 extends JFrame // used to create GUI for WK2MortgageCalc class {
// format to include 2 decimal places for dollar values
java.text.DecimalFormat dcm = new java.text.DecimalFormat("$,###.00");
// display elements for mortgage information in GUI
private JLabel mortgageAmountLabel = new JLabel(" Mortgage Loan Amount: "); //Mortgage Loan Amount label
private JTextField mortgageAmountTextField = new JTextField(10); // Mortgage Loan Amount text field

private JLabel mortgageInterestLabel = new JLabel(" Interest Rate (%):");// Interest Rate label
private JTextField mortgageInterestTextField = new JTextField(10); // Interest Rate text field

private JLabel mortgageTermLabel = new JLabel(" Term in Years:"); // mortgage Term in Years label
private JTextField mortgageTermTextField = new JTextField(10); // mortgage Term in Years text field

private JTextArea response = new JTextArea(10, 15);
JScrollPane scrollingResult = new JScrollPane(response); // results in text area created and scrolls

// JButton element
private JButton infoSubmitButton;// creates button to submit mortgage information in JPanel

public WK2MortCalcVer_2()// used to create JPanel container for mortgage infomration
infoSubmitButton = new JButton( "Calculate Monthly Payment (click)" ); // button with text
//add( infoSubmitButton );// add infoSubmitButton to JFrame

infoSubmitButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
// calling the clickCalculatePayment() method

}); // end button constructor
//Used to create the main center panel for input areas.
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout( 3,1 )); //Determines the layout of the panel.

//Used to add the labels and text fields for the pannel.
centerPanel.add( mortgageAmountLabel );
centerPanel.add( mortgageAmountTextField );
centerPanel.add( mortgageInterestLabel );
centerPanel.add( mortgageInterestTextField );
centerPanel.add( mortgageTermLabel );
centerPanel.add( mortgageTermTextField );
setLayout( new BorderLayout( 10,10 ) ); //Determines the borders of the panel.

//Used to add the center panel, result window, and submit button to the window.
add( centerPanel, BorderLayout.WEST );
add( scrollingResult, BorderLayout.SOUTH );
add( infoSubmitButton, BorderLayout.EAST );

//Used to ensure that the frame cannot be resised and that the window is visable.
setDefaultCloseOperation( EXIT_ON_CLOSE );
setResizable( true );
setTitle( "Mortgage Payment Calculator v. 2.0.1" );
setVisible( true );
// Calculates data input from GUI
public void clickCalculatePayment()
// GUI input
double mortgageAmount = Double.parseDouble( mortgageAmountTextField.getText() );
double mortgageInterest = Double.parseDouble( mortgageInterestTextField.getText() );
int mortgageTerm = Integer.parseInt( mortgageTermTextField.getText() );

// new version of the loan
mortgageLoan loan = new mortgageLoan(...
tracking img