DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    5

    Mortgage calculator help

    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
    }

  2. #2
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    >I am getting many errors
    Where are they?
    You need to copy them and post them here.

Similar Threads

  1. Mortgage Calculator Help Requested
    By Richbezza in forum C++
    Replies: 3
    Last Post: 05-09-2007, 02:16 AM
  2. Mortgage Calculator Help
    By vwrado in forum Java
    Replies: 7
    Last Post: 09-06-2005, 05:06 PM
  3. PowerBuilder project - Mortgage Industry
    By kremburlee in forum Careers
    Replies: 0
    Last Post: 06-29-2005, 03:36 PM
  4. Mortgage Calc - URGENT Help
    By chadonline in forum Java
    Replies: 1
    Last Post: 06-06-2005, 06:39 AM
  5. Mortgage Calcutator
    By Eric Dillard in forum Java
    Replies: 0
    Last Post: 06-06-2002, 10:12 AM

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links