School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,131 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,949 people online right now. Registration is fast and FREE... Join Now!



Mortgage Payment Calculator

Mortgage Payment Calculator Getting rid of these stupid errors Rate Topic: -----

#1 PhillyDiva1982  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 23
  • Joined: 09-December 08


Dream Kudos: 0

Post icon  Posted 11 May 2009 - 05:15 PM

HELP!!!!!!!!So for I've managed to go from 15 errors to 9 errors, what is it that I'm not seeing?

Write the program in Java (with a graphical user interface) so that it will allow the user to select which way they want to calculate a mortgage: by input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment or by input of the amount of a mortgage and then select from a menu of mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5 %
- 30 year at 5.75%

In either case, display the mortgage payment amount and then, list 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. Insert comments in the program to document the program.

*/

import java.awt.GridLayout.*;
import java.awt.event.ActionEvent.*;
import java.awt.event.ActionListener.*;
import java.text.NumberFormat.*;
import java.io.*;
import java.text.DecimalFormat.*;
import java.swing.*;
import java.text.*;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

 class Week4Mortgage extends JFrame implements ActionListener
{
	//create applets
	   private JLabel AmountofMortgage;
	   private JLabel RateofMortgage;
	   private JTextField PaymentofMortgage;
	   private JLabel Interest;
	   private JLabel TermofMortgage;
	   private JTextField AmountEntered;
	   private JTextField InterestEntered;
	   private JTextField TermEntered;
	   private JButton Calculate;
	   private JButton Clear;
	   private JButton Exit;

	   //declare variables
	   double AmountofMortgage;
	   double PaymentofMortgage;
	   double Interest;
	   double TermofMortage;
	   double RateofMortgage;


	   public Week4Mortgage();
		  {
			  super ("Mortgage calculator");
						  setSize (400,200);
						  setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
						  setVisible (true);
						  Container calc = getContentPane();
						  calc.setBackground (Color.lightGray);
						  GridBagLayout gblm = new GridBagLayout();
						GridLayout gridlayout= new GridLayout(5, 2, 20, 20);
						//GridBagConstraints gbc = new GridBagConstraints();
						calc.setLayout(gridlayout);

						AmountofMortgage = new JLabel("Enter the Amount of Loan");

								calc.add (AmountofMortgage,gridlayout);
								AmountEntered = new JTextField ();

								PaymentofMortgage = new JLabel("Enter the Payment of Loan");

								calc.add (PaymentofMortgage,gridlayout);
								AmountEntered = new JTextField();

								Interest = JLabel("Enter the Interest of the Loan");

								calc.add (Interest,gridlayout);
								AmountEntered = new JTextField();

								RateofMortgage = new JLabel("Enter the Rate of the Loan");

								calc.add (RateofMortgage,gridlayout);
								AmountEntered = new JTextField();


								//Display action listeners
								CalculateButton.addActionListener(this);
								ClearButton.addActionListener(this);
								ExitButton.addActionListener(this);



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

//method to calculate mortgage payment
public void  actionPerformed(ActionEvent e)
{
	boolean done = false;
	Object command = e.getSource();

	//display event for calculate button clicked
	if(command = calculateButton)
	{
		try
		{
			double AmountofMortgage = Double.parseDouble(a.getText());
			double TermofMortgage = Double.parseDouble(t.getText());
			double RateofMortgage = Double.parseDouble(r.getText());
			double Interest = (rate/100/12);
			double PaymentofMortgage = (principal*interest)/(1-Math.pow(1/(1+interest), term*12));
			String displayPayment = money.format(payment);

			//Display decimal point format
		DecimalFormat decimalPlaces=new DecimalFormat("0.00");


		//does not allow 0 or null value
		if(principal <=0 || rate <=0 || term<=0) throw new NumberFormatException();
		else done = true;
	}
	// use this to catch exception
	catch(NumberFormatException e)
	{
		JOptionPane.showMessageDialog("Your Monthtly Payment is ");
		JOptionPane.showMessageDialog(null, "This calculation does not work, Please try something else!");

	}

}

//display the code if user clicks the clear button
else if(command == clearButton)
{
	p.setText(null);
	r.setText(null);
	displayPayment.setText(null);
	paymentLabel.setText("Click the calculate button to display the payment amount");
}

//display the exit code
else if(command == exitButton)
{
	System.exit(0);
}

}

}

}


Was This Post Helpful? 0
  • +
  • -


#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • Icon
  • Group: Expert w/DIC++
  • Posts: 1,187
  • Joined: 06-March 09


Dream Kudos: 150

Posted 11 May 2009 - 11:16 PM

Hmm.. I can tell you what i'm not seeing. . .
Your errors that compiler is giving you.
Was This Post Helpful? 0
  • +
  • -

#3 PhillyDiva1982  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 23
  • Joined: 09-December 08


Dream Kudos: 0

Posted 12 May 2009 - 02:40 AM

View PostFuzzyness, on 11 May, 2009 - 11:16 PM, said:

Hmm.. I can tell you what i'm not seeing. . .
Your errors that compiler is giving you.


OOPS MY BAD.........HERE ARE THE ERRORS THAT THE COMPILER IS GIVING ME. :P

F:\Week4Mortgage.java:96: illegal start of expression
public static void main(String []args)
^
F:\Week4Mortgage.java:96: illegal start of expression
public static void main(String []args)
^
F:\Week4Mortgage.java:96: ';' expected
public static void main(String []args)
^
F:\Week4Mortgage.java:96: '.class' expected
public static void main(String []args)
^
F:\Week4Mortgage.java:96: ';' expected
public static void main(String []args)
^
F:\Week4Mortgage.java:102: illegal start of expression
public void actionPerformed(ActionEvent e)
^
F:\Week4Mortgage.java:102: illegal start of expression
public void actionPerformed(ActionEvent e)
^
F:\Week4Mortgage.java:102: ';' expected
public void actionPerformed(ActionEvent e)
^
F:\Week4Mortgage.java:102: ';' expected
public void actionPerformed(ActionEvent e)
^
9 errors

Tool completed with exit code 1
Was This Post Helpful? 0
  • +
  • -

#4 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • Icon
  • Group: Expert w/DIC++
  • Posts: 1,187
  • Joined: 06-March 09


Dream Kudos: 150

Posted 12 May 2009 - 01:09 PM

public Week4Mortgage();
You need to remove that semicolon, and I dont think I saw a closing bracket for that method either

This post has been edited by Fuzzyness: 12 May 2009 - 01:10 PM

Was This Post Helpful? 0
  • +
  • -

#5 PhillyDiva1982  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 23
  • Joined: 09-December 08


Dream Kudos: 0

Posted 12 May 2009 - 01:55 PM

View PostFuzzyness, on 12 May, 2009 - 01:09 PM, said:

public Week4Mortgage();
You need to remove that semicolon, and I dont think I saw a closing bracket for that method either


GOOD NOW I'M DOWN TO ONE ERROR.....


F:\Week4Mortgage.java:160: class, interface, or enum expected
}
^
1 error

Tool completed with exit code 1
Was This Post Helpful? 0
  • +
  • -

#6 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • Icon
  • Group: Expert w/DIC++
  • Posts: 1,187
  • Joined: 06-March 09


Dream Kudos: 150

Posted 12 May 2009 - 02:00 PM

You add the closing bracket to the constructor of Week4Mortagage?

If you did and still shows, please print the line of code it appears at

This post has been edited by Fuzzyness: 12 May 2009 - 02:01 PM

Was This Post Helpful? 0
  • +
  • -

#7 PhillyDiva1982  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 23
  • Joined: 09-December 08


Dream Kudos: 0

Posted 12 May 2009 - 03:54 PM

View PostFuzzyness, on 12 May, 2009 - 02:00 PM, said:

You add the closing bracket to the constructor of Week4Mortagage?

If you did and still shows, please print the line of code it appears at


Oh ok, I might have put the bracket in the wrong place. I'll try it again and see what happens. Also when you say print the line of code it appears at do you mean by writing "System.out.println?"
Was This Post Helpful? 0
  • +
  • -

#8 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • Icon
  • Group: Expert w/DIC++
  • Posts: 1,187
  • Joined: 06-March 09


Dream Kudos: 150

Posted 12 May 2009 - 04:31 PM

um, no I mean find the line of code that has the error, and copy and paste it in here...
Was This Post Helpful? 0
  • +
  • -

#9 PhillyDiva1982  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 23
  • Joined: 09-December 08


Dream Kudos: 0

Posted 12 May 2009 - 04:36 PM

View PostFuzzyness, on 12 May, 2009 - 04:31 PM, said:

um, no I mean find the line of code that has the error, and copy and paste it in here...



Here it is

F:\Week4Mortgage.java:162: class, interface, or enum expected
}
^
1 error

Tool completed with exit code 1
Was This Post Helpful? 0
  • +
  • -

#10 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • Icon
  • Group: Expert w/DIC++
  • Posts: 1,187
  • Joined: 06-March 09


Dream Kudos: 150

Posted 12 May 2009 - 04:37 PM

Well, you need to check all your brackets. I think you have an extra bracket somewhere

This post has been edited by Fuzzyness: 12 May 2009 - 04:42 PM

Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month