DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jan 2007

    Need help with Mortgage Calculator Program

    I am a student, so I'm not asking for a handout, just a little help from all of the experienced Java Gurus out there! For this week's assignment I am tasked to modify my mortgage calculator program to allow the user to input the amount of a mortgage and then select from a menu of mortgage loans: 7 years at 5.35%, 15 years at 5.5%, and 30 years at 5.75%. Use an array for the different loans. display the mortgage payment amount. Then, list the loan balance and interest paid for each payment over the term of the loan. The code posted below is my best work to reflect these changes, but my program will not execute. Can someone tell me why my program won't run and what is missing?


    //Created by Nathan Knarr on Jan 18, 2007//
    //Mortgage Calculator//

    import java.text.*;
    import javax.swing.*;
    import javax.swing.JComboBox;
    import java.awt.*;
    import java.awt.event.*;

    public class MortgageCalculator extends JFrame implements ActionListener
    private JPanel LabelPane;
    private JPanel FieldPane;
    private JPanel ButtonPane;
    private JLabel LoanAmt;
    private JLabel Term;
    private JLabel Rate;
    private JLabel MonthlyPymt;
    private JTextField TxtLoanAmt;
    private JTextField TxtTermRate;

    private JTextField TxtMthlyPymt;
    private JButton Calculate;
    private JComboBox;
    private String[] termRates = { "5 years @ 5.35%", "7 years @ 5.5%", "10 years @ 5.75%" };
    private JButton Reset;
    private JButton Exit;

    public MortgageCalculator ()
    //initialize and configure GUI

    setTitle("Nathan Knarr’s Mortgage Calculator");
    Toolkit theKit = this.getToolkit(); //Get the window toolkit
    Dimension wndSize = theKit.getScreenSize(); //Get screen size

    //Set the position to screen center & size to half screen size
    setBounds(wndSize.width/3, wndSize.height/3,wndSize.width/2, wndSize.height/2); // Size

    //Create Label panel and Labels
    JPanel LabelPane = new JPanel();
    LabelPane.setLayout(new GridLayout(4,1,0,60));
    JLabel LoanAmount = new JLabel("Enter loan amount without comma ");
    JLabel TermRate = new JLabel("Enter type of loan");
    new JLabel("Enter interest rate, i.e. 5.78, etc ");
    JLabel MonthlyPymt = new JLabel("Your monthly loan payment is $");

    //Add Labels to Label Panel


    //Create TextField Panel and TextFields
    JPanel FieldPane = new JPanel();
    FieldPane.setLayout(new GridLayout(4,1,0,60));{
    TxtLoanAmt = new JTextField(5);
    //TxtTermRate = new JTextField(5);

    //TxtMthlyPymt = new JTextField(5);
    myComboBox = new JComboBox(termRates);
    //Add Fields to Field Panel



    //Create Button Panel and Button
    JPanel ButtonPane = new JPanel();
    JButton Calculate = new JButton("Calculate"); //button used to calculate mortgage payment
    JButton Reset = new JButton("Reset"); //button used to clear data from the fields
    JButton Exit = new JButton("Exit"); // Exit button added
    ButtonPane.add(Calculate); // Add to JPanel
    ButtonPane.add(Reset); // Reset button added to JPanel
    ButtonPane.add(Exit); // Exit button added to Panel

    //Add panels to container of window
    Container content = this.getContentPane();
    content.setLayout(new BorderLayout());
    content.add(LabelPane, BorderLayout.WEST);
    content.add(FieldPane, BorderLayout.CENTER);
    content.add(ButtonPane, BorderLayout.SOUTH);

    //Set action commands for the text fields


    public void myComboBox.getSelectIndex(); //setResultValue()
    double amount = Double.parseDouble (TxtLoanAmt.getText());

    int term = Integer.parseInt(TxtTerm.getText())*12;

    double rate = Double.parseDouble (TxtRate.getText()) / 100;

    double result = (amount*(rate/12)) / (1 - 1 /Math.pow((1 + rate/12), term));

    //Format results with two decimals
    DecimalFormat twoDigits = new DecimalFormat("$#,000.00");

    TxtMthlyPymt.setText(twoDigits.format (result));

    public void actionPerformed(ActionEvent ae)
    if (ae.getActionCommand().equals("Calculate"))

    else if (ae.getActionCommand().equals("Reset"))

    else if (ae.getActionCommand().equals("Exit"))

    public static void main(String[] args)
    MortgageCalculator frame = new MortgageCalculator();

  2. #2
    Join Date
    Oct 2005
    New Jersey
    I bet your code doesn't compile yet. Some of the things which are too obvious

    private JComboBox;
    You are supposed to declare a variable here.

    public void myComboBox.getSelectIndex();
    You have neither declared a method nor a variable here.

    Your opening and closing braces are misplaced.

    There might be a couple more things to check besides that.
    Happiness is good health and a bad memory.

Similar Threads

  1. Mortgage Calculator Help Requested
    By Richbezza in forum C++
    Replies: 3
    Last Post: 05-09-2007, 02:16 AM
  2. Code Help with GUI Mortgage Calculator
    By drewdat7001 in forum Java
    Replies: 4
    Last Post: 12-20-2006, 12:55 AM
  3. Help With GUI Mortgage Calculator
    By drewdat7001 in forum Java
    Replies: 1
    Last Post: 10-29-2006, 11:34 PM
  4. Replies: 7
    Last Post: 03-07-2006, 04:34 PM
  5. Mortgage calculator help
    By vwrado in forum Java
    Replies: 1
    Last Post: 09-26-2005, 05:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.