mortgage payment amount from user input of the amount of the mortgage and the user's
selection from a menu of available mortgage loans:
- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%
Use an array for the mortgage data for the different loans. Display the mortgage payment amountfollowed by the loan balance and interest paid for each payment over the term of the loan. Allow
the user to loop back and enter a new amount and make a new selection or quit. Please insert
comments in the program to document the program.
Here are my errors:
double cannot be dereferenced Line 112
double cannot be dereferenced Line 113
Here is my code:
/** Mortgage Calculator Program
* Week 2 PRG421
*Change Request #4
*Requestor: Ninfa Pendleton - Rapid City, SD
*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.
*
*Author: Stacey Estey
*Due August 30, 2010*/
//import needed packages
import java.awt.*;
import javax.swing.*;
import javax.swing.JComboBox;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
//declare calculator class
public class Calculator extends JFrame implements ActionListener
{
private JFrame frame;
private JPanel panelAdder;
private JLabel labelAmount;
private JLabel labelTerm;
private JLabel labelRate;
private JTextField textFieldAmount;
private JTextField textFieldMonthlyPayment;
private JComboBox termList;
private JComboBox rateList;
private JButton buttonCalc;
public Calculator()
{
initComponents();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setTitle("Mortgage Calculator");
pack();
// Add Listeners
buttonCalc.addActionListener(this);
}
public void initComponents()
{
//strings for combo boxes
String [] termString = {"7", "15", "30"};
String [] rateString = {"0.535", "0.055", "0.0575"};
//Initialize Components
frame = new JFrame();
panelAdder = new JPanel();
labelAmount = new JLabel("Amount");
textFieldAmount = new JTextField();
labelTerm = new JLabel("Term");
termList = new JComboBox(termString);
labelRate = new JLabel("Rate");
rateList = new JComboBox(rateString);
textFieldMonthlyPayment = new JTextField();
buttonCalc = new JButton("Calculate");
//Set Object Attributes
textFieldMonthlyPayment.setEditable(false);
textFieldMonthlyPayment.setColumns(12);
textFieldAmount.setColumns(8);
termList.setSelectedIndex(2);
termList.addActionListener(this);
rateList.setSelectedIndex(2);
rateList.addActionListener(this);
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
// add the components to the panel
panelAdder.add(labelAmount);
panelAdder.add(textFieldAmount);
panelAdder.add(labelTerm);
panelAdder.add(termList);
panelAdder.add(labelRate);
panelAdder.add(rateList);
panelAdder.add(buttonCalc);
panelAdder.add(textFieldMonthlyPayment);
contentPane.add(panelAdder);
}
public static void main(String[] args)
{
Calculator frame = new Calculator();
}
private void setMonthlyPaymentValue()
{
DecimalFormat formatter = new DecimalFormat("$#,##0.00");
double amount = Double.parseDouble(textFieldAmount.getText()); //get user input--mortgage amount
double termList = Double.toString(termString(termList.getSelectedItem()))* 12 ; //get user input--term of mortgage in years
double rateList = Double.toString(rateString(rateList.getSelectedItem()))/ 12 ; // get user input--interest rate
double monthlyPayment = amount * Math.pow(1+rateList, termList) * rateList /(Math.pow(1+rateList , termList)-1); //calculate input display monthly payment amount.
textFieldMonthlyPayment.setText(" " + formatter.format(monthlyPayment));
}
public void actionPerformed(ActionEvent event)
{
String command = event.getActionCommand();
if (command == "Calculate") {
setMonthlyPaymentValue();
}
}
}
This is as far as I have got. I am stuck trying to getting these lines of code right so I can move on to trying to get the rest done. Any advice would be greatly appreciated.

New Topic/Question
Reply




MultiQuote








|