Prg 421 Week 2 Program - Change Request #4

Topics: Mortgage loan, Graphical user interface, Interest Pages: 5 (582 words) Published: March 19, 2012
/*

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.io.*;
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
clickCalculatePayment();
}

}); // 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.
pack();
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(...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • LAW 421 week 2 reflection Essay
  • PRG 421 Week 1 Essay
  • MKT 421 week 4 Essay
  • Law 421 Week 2 Essay
  • Essay on Week 4 Assignment 2
  • Essay about LAW 421 week 4 Big Time Toymaker
  • week 4 lab 2 Essay
  • Law 421 Week 4 Assignment Essay

Become a StudyMode Member

Sign Up - It's Free