ReviewEssays.com - Term Papers, Book Reports, Research Papers and College Essays
Search

Java Calculator

Essay by   •  February 18, 2011  •  Research Paper  •  3,979 Words (16 Pages)  •  1,286 Views

Essay Preview: Java Calculator

Report this essay
Page 1 of 16

/*

Mortgage Calculator

Date: April 16, 2008

Filename: MortgageCalc.java

Purpose: This is a program to calculate the mortgage using user input.

*/

import java.awt.*;

import java.awt.event.*;

import java.awt.datatransfer.*;

import java.text.DecimalFormat;

import javax.swing.JOptionPane;

public class MortgageCalc extends Frame implements ActionListener

{

private Button keys[];

private Panel userInterface, buttonInterface, result1Interface, result2Interface;

private TextField tfMortgagePayment, tfMortgageAmount;

private TextArea tfMonthlyPayments;

private Label label1, label2, label3, label4;

private Choice availableLoans;

private double mortgagePayment, loanBalance=0;

private boolean foundKey;

private DecimalFormat roundDecimal;

private double [] intRateAnnual = {5.35, 5.50, 5.75};

private int termMonths, arrayIndex=0;

private int [] termYears = {7, 15, 30};

//MortgageCalc constructor

public MortgageCalc() //throws IOException

{

roundDecimal = new DecimalFormat("########.##");

// create an instance of the menu

MenuBar mnuBar = new MenuBar();

setMenuBar(mnuBar);

// construct and populate the File menu

Menu mnuFile = new Menu("File", true);

mnuBar.add(mnuFile);

MenuItem mnuFileExit = new MenuItem("Exit");

mnuFile.add(mnuFileExit);

// construct and populate the Edit menu

Menu mnuEdit = new Menu("Edit", true);

mnuBar.add(mnuEdit);

MenuItem mnuEditClear = new MenuItem("Clear");

mnuEdit.add(mnuEditClear);

// construct and populate the About menu

Menu mnuAbout = new Menu("About", true);

mnuBar.add(mnuAbout);

MenuItem mnuAboutCalculator = new MenuItem("Mortgage Calculator");

mnuAbout.add(mnuAboutCalculator);

// add the ActionListener to each menu item

mnuFileExit.addActionListener(this);

mnuEditClear.addActionListener(this);

mnuAboutCalculator.addActionListener(this);

// assign an ActionCommand to each menu item

mnuFileExit.setActionCommand("Exit");

mnuEditClear.setActionCommand("Clear");

mnuAboutCalculator.setActionCommand("About");

// construct components and initialize beginning values

tfMortgageAmount = new TextField(20);

tfMortgageAmount.setEditable(true);

tfMortgagePayment = new TextField(20);

tfMortgagePayment.setEditable(false);

tfMonthlyPayments = new TextArea("",5,55);

tfMonthlyPayments.setEditable(false);

userInterface = new Panel();

buttonInterface = new Panel();

result1Interface = new Panel();

result2Interface = new Panel();

//These create the labels for the text fields

label1 = new Label();

label2 = new Label();

label3 = new Label();

label4 = new Label();

label1.setText("Mortgage Amount: ");

label2.setText("Available Loan: ");

label3.setText("Payment Summary: ");

label4.setText("Mortgage Payment: ");

//This creates the drop down

availableLoans = new Choice();

availableLoans.addItem("7 years at 5.35%");

availableLoans.addItem("15 years at 5.5%");

availableLoans.addItem("30 years at 5.75%");

//This is for the two buttons

keys = new Button[2];

// construct and assign captions to the Buttons

keys[0] = new Button("Calculate");

keys[1] = new Button("Clear");

...

...

Download as:   txt (12.4 Kb)   pdf (133.9 Kb)   docx (13.7 Kb)  
Continue for 15 more pages »
Only available on ReviewEssays.com