Hi I am in need of some help for modifying my mortgage calculator program for my java class.
I am getting many errors as I dont know how to fix it. Can anyone point me in the right direction?
Thanks in advance.
Code://pos407 //9-16-2005 import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane; // import class JOptionPane import java.text.DecimalFormat; // import class DecimalFormat public class W2_tran extends JFrame implements ActionListener { static DecimalFormat decmat = new DecimalFormat("$#,##0.00"); FlowLayout flow = new FlowLayout(); JLabel amount1 = new JLabel("Amount: "); JTextField amount = new JTextField(10); JLabel rate1 = new JLabel("Rate: "); JTextField rate = new JTextField(4); JLabel term1 = new JLabel("Term: "); JTextField term = new JTextField(4); JComboBox mortgageBox = new JComboBox(); JLabel mortgageList = new JLabel("<html><font face='Tahoma' size='5'>Mortgage</font></html>"); JButton calcButton = new JButton("Calculate Total"); JButton exitButton = new JButton("Exit"); JButton reset = new JButton("Reset"); JLabel blankSpaces1 = new JLabel(" "); JLabel blankSpaces2 = new JLabel(" "); JLabel result = new JLabel("<html><h1>The total is </h1></html>"); JLabel sum = new JLabel(""); public W2_tran() { Container con = getContentPane(); con.setLayout(flow);// places components in a row con.add(amount1); con.add(amount); con.add(rate1); con.add(rate); con.add(term1); con.add(term); con.add(calcButton); con.add(blankSpaces1); con.add(result); con.add(sum); mortgageBox.addItem("Mortage Inputs Above"); mortgageBox.addItem(" 7-year Mortgage at 5.35%"); mortgageBox.addItem("15-year Mortgage at 5.5%"); mortgageBox.addItem("30-year Mortgage at 5.75%"); con.add(blankSpaces2); con.add(exitButton); con.add(reset); con.add(mortgageList); con.add(mortgageBox); amount.setBackground(Color.cyan); rate.setBackground(Color.cyan); term.setBackground(Color.cyan); calcButton.setForeground(Color.red); calcButton.setBackground(Color.yellow); exitButton.setForeground(Color.black); exitButton.setBackground(Color.yellow); reset.setForeground(Color.black); reset.setBackground(Color.yellow); mortgageBox.addActionListener(this); mortgageBox.setForeground(Color.white); mortgageBox.setBackground(Color.black); con.setBackground(Color.white);//sets the background color calcButton.addActionListener(this); exitButton.addActionListener(this); reset.addActionListener(this); } public static void main(String[] args) { W2_tran cFrame = new W2_tran(); cFrame.setTitle("Mortgage Calculator"); cFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cFrame.setSize(400,300); cFrame.setVisible(true); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if(source == calcButton) { try { String amount1 = amount.getText(); String rate1 = term.getText(); String term1 = rate.getText(); double a1 = Double.parseDouble(amount1); double r1 = Double.parseDouble(rate1); if(r1 == 0) getCleanScreen(); double t1 = Double.parseDouble(term1); if(t1 == 0) getCleanScreen(); // formats numbers to display only two decimal places // different decimal formats ensure $ sign & "0.00" print wherever needed java.text.DecimalFormat dec = new java.text.DecimalFormat(",##0.00"); java.text.DecimalFormat doldec = new java.text.DecimalFormat("$,##0.00"); double mortgagefigure = getPayment(a1, r1, t1, 12); double total = getFigure(mortgagefigure); String output = "" + doldec.format(total); sum.setText("<html><div align='center'><font face='Tahoma' size='5' color='blue'>"+output+"</font></div></html>"); } catch (NumberFormatException error) { getCleanScreen(); } } else if (source == mortgageBox) { int sizeNum = mortgageBox.getSelectedIndex(); if (sizeNum == 0) try { getCleanScreen(); } catch (NumberFormatException error) { getCleanScreen(); } else if (sizeNum == 1) { try { String amount1 = amount.getText(); double a1 = Double.parseDouble(amount1); double r1 = 7; double t1 = 5.35; // formats numbers to display only two decimal places // different decimal formats ensure $ sign & "0.00" print wherever needed java.text.DecimalFormat dec = new java.text.DecimalFormat(",##0.00"); java.text.DecimalFormat doldec = new java.text.DecimalFormat("$,##0.00"); double mortgagefigure = getPayment(a1, r1, t1, 12); double total = getFigure(mortgagefigure); String output = "" + doldec.format(total); rate.setText(""); term.setText(""); sum.setText("<html><div align='center'><font face='Tahoma' size='5' color='blue'>"+output+"</font></div></html>"); } catch (NumberFormatException error) { getCleanScreen(); } } else if (sizeNum == 2) { try { String amount1 = amount.getText(); double a1 = Double.parseDouble(amount1); double r1 = 15; double t1 = 5.5; // formats numbers to display only two decimal places // different decimal formats ensure $ sign & "0.00" print wherever needed java.text.DecimalFormat dec = new java.text.DecimalFormat(",##0.00"); java.text.DecimalFormat doldec = new java.text.DecimalFormat("$,##0.00"); double mortgagefigure = getPayment(a1, r1, t1, 12); double total = getFigure(mortgagefigure); String output = "" + doldec.format(total); rate.setText(""); term.setText(""); sum.setText("<html><div align='center'><font face='Tahoma' size='5' color='blue'>"+output+"</font></div></html>"); } catch (NumberFormatException error) { getCleanScreen(); } } else { try { String amount1 = amount.getText(); double a1 = Double.parseDouble(amount1); double r1 = 30; double t1 = 5.75; // formats numbers to display only two decimal places // different decimal formats ensure $ sign & "0.00" print wherever needed java.text.DecimalFormat dec = new java.text.DecimalFormat(",##0.00"); java.text.DecimalFormat doldec = new java.text.DecimalFormat("$,##0.00"); double mortgagefigure = getPayment(a1, r1, t1, 12); double total = getFigure(mortgagefigure); String output = "" + doldec.format(total); rate.setText(""); term.setText(""); sum.setText("<html><div align='center'><font face='Tahoma' size='5' color='blue'>"+output+"</font></div></html>"); } catch (NumberFormatException error) { getCleanScreen(); } } } else if(source == resetButton) { getCleanScreen(); } else { // if the user clicks on the Exit button (source is Exit button) System.exit(0); } }// end actionPerformed }


Reply With Quote


Bookmarks