3 Replies - 2650 Views - Last Post: 01 April 2009 - 06:36 PM Rate Topic: -----

#1 kalibballer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-March 09

Mortgage Calculator Help

Posted 31 March 2009 - 11:55 PM

i need help with my assignment for this week. i need 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.
i get this error
Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at calculator.main(calculator.java:131)
Can someone tell me why my program won't run properly and what is missing? any help will be appreciated thanks

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


public class calculator 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 calculator ()
{
//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
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

//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
LabelPane.add(LoanAmount);
//LabelPane.add(TermRate);

//LabelPane.add(MonthlyPymt);

//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
FieldPane.add(TxtLoanAmt);


//FieldPane.add(TxtTermRate);

//FieldPane.add(TxtMthlyPymt);

//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
Calculate.addActionListener(this);
Reset.addActionListener(this);
Exit.addActionListener(this);

this.setVisible(true);}
}

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"))
{
setResultValue();
}

else if (ae.getActionCommand().equals("Reset"))
{
TxtLoanAmt.setText("");
TxtTermRate.setText("");

TxtMthlyPymt.setText("");
}
else if (ae.getActionCommand().equals("Exit"))
{
System.exit(0);
}
}

public static void main(String[] args)
{
calculator frame = new calculator();
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: Mortgage Calculator Help

#2 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Mortgage Calculator Help

Posted 01 April 2009 - 12:34 AM

Welcome!

Please edit your post above to add the code tags:

:code:

Thanks!
Was This Post Helpful? 0
  • +
  • -

#3 kalibballer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-March 09

Re: Mortgage Calculator Help

Posted 01 April 2009 - 12:39 AM

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


public class calculator 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 calculator ()
{
//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
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

//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
LabelPane.add(LoanAmount);
//LabelPane.add(TermRate);

//LabelPane.add(MonthlyPymt);

//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
FieldPane.add(TxtLoanAmt);


//FieldPane.add(TxtTermRate);

//FieldPane.add(TxtMthlyPymt);

//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
Calculate.addActionListener(this);
Reset.addActionListener(this);
Exit.addActionListener(this);

this.setVisible(true);}
}

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"))
{
setResultValue();
}

else if (ae.getActionCommand().equals("Reset"))
{
TxtLoanAmt.setText("");
TxtTermRate.setText("");

TxtMthlyPymt.setText("");
}
else if (ae.getActionCommand().equals("Exit"))
{
System.exit(0);
}
}

public static void main(String[] args)
{
calculator frame = new calculator();
}
} 


Was This Post Helpful? 0
  • +
  • -

#4 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Mortgage Calculator Help

Posted 01 April 2009 - 06:36 PM

I see these errors:
calculator.java:26: <identifier> expected
    private JComboBox ;
calculator.java:103: '(' expected
             public void myComboBox.getSelectIndex(); //setResultValue()
calculator.java:103: invalid method declaration; return type required
             public void myComboBox.getSelectIndex(); //setResultValue()
3 errors
BUILD FAILED (total time: 0 seconds)


This post has been edited by n8wxs: 01 April 2009 - 06:37 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1