Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 306,813 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,690 people online right now. Registration is fast and FREE... Join Now!




Mortgage Payment Calculator

 

Mortgage Payment Calculator, Getting rid of these stupid errors

PhillyDiva1982

11 May, 2009 - 05:15 PM
Post #1

New D.I.C Head
*

Joined: 9 Dec, 2008
Posts: 23

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

CODE
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);
}

}

}

}


User is offlineProfile CardPM
+Quote Post


Fuzzyness

RE: Mortgage Payment Calculator

11 May, 2009 - 11:16 PM
Post #2

Comp Sci Student
Group Icon

Joined: 6 Mar, 2009
Posts: 1,183



Thanked: 181 times
Dream Kudos: 150
My Contributions
Hmm.. I can tell you what i'm not seeing. . .
Your errors that compiler is giving you.
User is offlineProfile CardPM
+Quote Post

PhillyDiva1982

RE: Mortgage Payment Calculator

12 May, 2009 - 02:40 AM
Post #3

New D.I.C Head
*

Joined: 9 Dec, 2008
Posts: 23

QUOTE(Fuzzyness @ 11 May, 2009 - 11:16 PM) *

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. tongue.gif

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

User is offlineProfile CardPM
+Quote Post

Fuzzyness

RE: Mortgage Payment Calculator

12 May, 2009 - 01:09 PM
Post #4

Comp Sci Student
Group Icon

Joined: 6 Mar, 2009
Posts: 1,183



Thanked: 181 times
Dream Kudos: 150
My Contributions
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
User is offlineProfile CardPM
+Quote Post

PhillyDiva1982

RE: Mortgage Payment Calculator

12 May, 2009 - 01:55 PM
Post #5

New D.I.C Head
*

Joined: 9 Dec, 2008
Posts: 23

QUOTE(Fuzzyness @ 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


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

User is offlineProfile CardPM
+Quote Post

Fuzzyness

RE: Mortgage Payment Calculator

12 May, 2009 - 02:00 PM
Post #6

Comp Sci Student
Group Icon

Joined: 6 Mar, 2009
Posts: 1,183



Thanked: 181 times
Dream Kudos: 150
My Contributions
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
User is offlineProfile CardPM
+Quote Post

PhillyDiva1982

RE: Mortgage Payment Calculator

12 May, 2009 - 03:54 PM
Post #7

New D.I.C Head
*

Joined: 9 Dec, 2008
Posts: 23

QUOTE(Fuzzyness @ 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


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?"

User is offlineProfile CardPM
+Quote Post

Fuzzyness

RE: Mortgage Payment Calculator

12 May, 2009 - 04:31 PM
Post #8

Comp Sci Student
Group Icon

Joined: 6 Mar, 2009
Posts: 1,183



Thanked: 181 times
Dream Kudos: 150
My Contributions
um, no I mean find the line of code that has the error, and copy and paste it in here...
User is offlineProfile CardPM
+Quote Post

PhillyDiva1982

RE: Mortgage Payment Calculator

12 May, 2009 - 04:36 PM
Post #9

New D.I.C Head
*

Joined: 9 Dec, 2008
Posts: 23

QUOTE(Fuzzyness @ 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...



Here it is

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

Tool completed with exit code 1
User is offlineProfile CardPM
+Quote Post

Fuzzyness

RE: Mortgage Payment Calculator

12 May, 2009 - 04:37 PM
Post #10

Comp Sci Student
Group Icon

Joined: 6 Mar, 2009
Posts: 1,183



Thanked: 181 times
Dream Kudos: 150
My Contributions
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
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:03PM

Live Java Help!

Be Social

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

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month