Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Java Program error need help

Thread view: 
immortalk1@gmail.com - 17 Oct 2006 02:53 GMT
I am working on this program for class and I can't figure out why I am
getting class or interface expected on the last two { symbols. Please
help, I am not trying to cheat, just need a point in the write
direction. Thank you

/*

 Author:  Kevin Rosier
 Course:  POS 407
 Assignment:  Week 3 Mortgage Calculator
 Written:  Oct 16, 2006

 Creates a sales tax calculator with a GUI.

*/

// class names
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.text.*;
import java.util.*;
import javax.*;

public class MortgageCalculatorGUIwk3 extends JFrame implements
ActionListener
{

        JFrame mortgageFrame;
        JPanel mortgagePanel;
        JButton mortgageButton;
        JButton clearButton;
        JButton exitButton;
        JLabel mortgageLabel;
        JLabel interestrateLabel;
        JLabel yearLabel;
        JLabel paymentLabel;
        JTextField mortgageField;
        JTextField interestrateField;
        JTextField yearField;
        JTextField paymentField;

    public MortgageCalculatorGUIwk3() //constructor
{
    {
        // defining JFrame

                mortgageFrame = new JFrame("Calculate Your Mortgage Payment");
                mortgageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                mortgageFrame.setSize(500,500);

                //public static void main(String args[]){

                    ActionListener actionListener = new ActionListener() {
                        public void actionPerformed(ActionEvent actionEvent) {
                            AstractionButton aButton = (AbstractButton)
actionEvent.getSource();

                        boolean selected = abutton.getmodel().isSelected();
                        System.out.println(actionEvent.getActionCommand()
                            + " - selected? " + selected);
                        }
                };

                                //constructs Radio buttons
                                JMenuBar menuBar = new JMenuBar();
                                JMenu menu = new JMenu("Menu");
                                ButtonGroup buttonGroup = new ButtonGroup();
                                menu.setMnemonic(KeyEvent.VK_M);

                                JRaidoButtonMenuItem emptyMenuItem = new
JRadioButtonMenuItem();
                                empyMenuItem.setActionCommand("Empty");
                                emptyMenuItem.addActionListener(actionListener);
                                buttonGroup.add(emptyMenuItem);
                                menu.add(empyMenuItem);

                                JRadioButtonMenuItem oneMenuItem = new JRadioButtonMenuItem("7
years at 5.35%");
                                oneMenuItem.addActionListener(actionListener);
                                buttonGroup.add(oneMenuItem);
                                menu.add(oneMenuItem);

                                JRadioButtonMenuItem twoMenuItem = new JRadioButtonMenuItem("15
years at 5.5%");
                                twoMenuItem.addActionListener(actionListener);
                                buttonGroup.add(twoMenuItem);
                                menu.add(twoMenuItem);

                                JRadioButtonMenuItem threeMenuItem = new
JRadioButtonMenuItem("30 years 5.75%");
                                threeMenuItem.addActionListener(actionListener);
                                buttonGroup.add(threeMenuItem);
                                menu.add(threeMenuItem);

                                menuBar.add(menu);
                                frame.setJMenuBar(menuBar);
                                frame.setSize(350, 250);
                                frame.setVisible(true);

        // defining JPanel

                JPanel mortgagePanel = new JPanel(new GridLayout(7,2,10,30));

        // defining contents on the panel

                mortgageLabel = new JLabel("Mortgage Amount Desired");
                interestrateLabel = new JLabel("Interest Rate Desired");
                yearLabel = new JLabel("Years of Mortgage");
                paymentLabel = new JLabel("Payment");

                mortgageButton = new JButton("Your Monthly Payment Is");
                clearButton = new JButton("Reset");
                exitButton = new JButton("Exit");

        // data for calculations

                mortgageField = new JTextField("");
                interestrateField = new JTextField("");
                yearField = new JTextField("");
                paymentField = new JTextField("");
                paymentField.setEditable(false);

        // Adding components to the GUI
                mortgagePanel.add(mortgageLabel);
                mortgagePanel.add(mortgageField);
                mortgagePanel.add(interestrateLabel);
                mortgagePanel.add(interestrateField);
                mortgagePanel.add(yearLabel);
                mortgagePanel.add(yearField);
                mortgagePanel.add(mortgageButton);
                mortgagePanel.add(clearButton);
                mortgagePanel.add(exitButton);
                mortgagePanel.add(paymentLabel);
                mortgagePanel.add(paymentField);

                mortgageFrame.add(mortgagePanel);
                mortgageFrame.setVisible(true);

        // action buttons

                mortgageButton.addActionListener(this);
                clearButton.addActionListener(this);
                exitButton.addActionListener(this);

        }
    } //end constructor

        // What action is to be performed

        public void actionPerformed(ActionEvent e)

    {
        Object source = e.getSource();
        if(source == mortgageButton) {

                String sMortgage = mortgageField.getText();
                String sInterestrate = interestrateField.getText();
                String sYear = yearField.getText();

                    double mortgage = Double.parseDouble(sMortgage);
                    double interestrate = Double.parseDouble(sInterestrate);
                    double year = Double.parseDouble(sYear);

                double numberOfPayments = year * 12;
                double monthlyInterest = interestrate / 100 / 12;
                double x = Math.pow(1+monthlyInterest, numberOfPayments);

                    double monthlyPayment = (mortgage * x * monthlyInterest)/(x-1);

                DecimalFormat df = new DecimalFormat("$0,000.00");
                paymentField.setText(df.format(monthlyPayment));

    }
        else if(source == clearButton)
    {
            mortgageField.setText("");
            interestrateField.setText("");
            yearField.setText("");
    }
        else if(source == exitButton)
    {
            System.exit(0);
    }

} // end actionPerformed

        public static void main(String [] args) {

        MortgageCalculatorGUIwk3 thisCalc = new MortgageCalculatorGUIwk3();

             };  //end main
        };

    }   //end class
}
Lionel - 17 Oct 2006 03:03 GMT
I can't read much of the code below because the formatting has come
through awful. I have made one point though, see below:

> I am working on this program for class and I can't figure out why I am
> getting class or interface expected on the last two { symbols. Please
[quoted text clipped - 42 lines]
> {
>     {

What's going on here? Why have you got two opening braces? Make sure all
your braces line up before compiling again. It should be pretty easy to
check in an IDE such as Netbeans.

Lionel.
immortalk1@gmail.com - 17 Oct 2006 03:17 GMT
I am new to this so I am not sure what you mean, I lined up all the {
and it does not seem to help

> I can't read much of the code below because the formatting has come
> through awful. I have made one point though, see below:
[quoted text clipped - 51 lines]
>
> Lionel.
Lionel - 17 Oct 2006 03:59 GMT
> I am new to this so I am not sure what you mean, I lined up all the {
> and it does not seem to help

What I mean by line up is that you need to make sure that for every {
there is a corresponding }. If you aren't sure where braces should go
then there is a far bigger problem.

>> I can't read much of the code below because the formatting has come
>> through awful. I have made one point though, see below:
[quoted text clipped - 51 lines]
>>
>> Lionel.
Holmbrew - 17 Oct 2006 03:32 GMT
You have a number of errors. Get an IDE like Eclipse or NetBeans, and
you will have an easier time.

You should look carefully look at the JFrame variable and there
spelling errors for a few of your fields.  Also the last curly brace in
you class is an extra.  You also do not need the semicolons after the
curly braces in a POJO class like this.

On Oct 16, 7:53 pm, immorta...@gmail.com wrote:
> I am working on this program for class and I can't figure out why I am
> getting class or interface expected on the last two { symbols. Please
[quoted text clipped - 192 lines]
>
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.