Results 1 to 3 of 3

Thread: Need some help.

  1. #1
    Sol61 is offline Member
    Join Date
    May 2016
    Posts
    2
    Rep Power
    0

    Default Need some help.

    My assignment is this:
    Design a GUI program to find the weighted average of four test scores. The four test scores and their respective weights are given in the following format:

    testscore1 weight1
    ...

    For example, the sample data is as follows:

    75 0.20
    95 0.35
    85 0.15
    65 0.30

    The user is supposed to enter the data and press a Calculate button. The program must display the weighted average.

    I have written the code but getting error after error. Here is my code followed by the errors messages.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.DecimalFormat;

    public class MOD6A extends JFrame
    {

    private JLabel blankoneL, blanktwoL,
    blankthreeL, scoreL,
    weightL, oneL, twoL,
    threeL,fourL,averageL;


    private JTextField oneTF, twoTF, threeTF,
    fourTF, woneTF, wtwoTF,

    wthreeTF, wfourTF, averageTF;


    private JButton calculateB, exitB;

    private CalculateButtonHandler cbHandler;
    private ResetButtonHandler rbHandler;

    private ExitButtonHandler ebHandler;

    //indicate the size of the window

    private static final int WIDTH = 500;

    private static final int HEIGHT = 400;


    public MOD6A()
    {
    //Create labels

    blankoneL = new JLabel("");

    blanktwoL = new JLabel("");

    blankthreeL = new JLabel("");

    scoreL = new JLabel("Score", SwingConstants.CENTER);//swingConstants.XXXX tells the program how to align the text in the window

    weightL = new JLabel("Weight", SwingConstants.CENTER);

    oneL = new JLabel("Test Score One: ", SwingConstants.RIGHT);

    twoL = new JLabel("Test Score Two: ", SwingConstants.RIGHT);

    threeL = new JLabel("Test Score Three: ", SwingConstants.RIGHT);

    fourL = new JLabel("Test Score Four: ", SwingConstants.RIGHT);

    averageL = new JLabel("Weighted Average: ", SwingConstants.RIGHT);


    //Create textfields

    oneTF = new JTextField(5);

    twoTF = new JTextField(5);

    threeTF = new JTextField(5);

    fourTF = new JTextField(5);

    woneTF = new JTextField(5);

    wtwoTF = new JTextField(5);

    wthreeTF = new JTextField(5);

    wfourTF = new JTextField(5);

    averageTF = new JTextField(5);


    //create Submit Button

    calculateB = new JButton("Submit");

    cbHandler = new CalculateButtonHandler();

    calculateB.addActionListener(cbHandler);

    //Create Reset Button

    resetB = new JButton("Reset");

    rbHandler = new ResetButtonHandler();

    resetB.addActionListener(rbHandler);



    //Create Exit Button

    exitB = new JButton("Exit");

    ebHandler = new ExitButtonHandler();

    exitB.addActionListener(ebHandler);


    //Set the title of the window

    setTitle("Evaluate 6 IT145");


    //Get the container

    Container pane = getContentPane();


    //Set the layout

    pane.setLayout(new GridLayout(7,3));


    //Place the components in the pane

    pane.add(blankoneL);

    pane.add(scoreL);

    pane.add(weightL);

    //first row

    pane.add(oneL);

    pane.add(oneTF);

    pane.add(woneTF);

    //second row

    pane.add(twoL);

    pane.add(twoTF);

    pane.add(wtwoTF);
    //third row

    pane.add(threeL);

    pane.add(threeTF);

    pane.add(wthreeTF);

    //fourth row

    pane.add(fourL);

    pane.add(fourTF);

    pane.add(wfourTF);

    //fifth row
    pane.add(averageL);

    pane.add(averageTF);

    pane.add(blanktwoL);

    //sixth row
    pane.add(calculateB);

    pane.add(blankthreeL);


    //seventh row
    pane.add(exitB);

    //set the size of the window and display it

    setSize(WIDTH, HEIGHT);

    setVisible(true);

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    }


    private class CalculateButtonHandler implements ActionListener
    {

    public void actionPerformed(ActionEvent e)
    {

    }


    double one, wone, two, wtwo,

    three, wthree, four, wfour, ave;


    DecimalFormat twoDigits = new DecimalFormat("0.00");

    one = Double.parseDouble(oneTF.getText());

    wone = Double.parseDouble(woneTF.getText());

    two = Double.parseDouble(twoTF.getText());

    wtwo = Double.parseDouble(wtwoTF.getText());

    three = Double.parseDouble(threeTF.getText());

    wthree = Double.parseDouble(wthreeTF.getText());

    four = Double.parseDouble(fourTF.getText());

    wfour = Double.parseDouble(wfourTF.getText());

    ave = (one * wone + two * wtwo + three * wthree

    + four * wfour)/(wone+wtwo+wthree+wfour);

    averageTF.setText(""+ twoDigits.format(ave));

    }

    }


    private class ExitButtonHandler implements ActionListener
    {

    public void actionPerformed(ActionEvent e)
    {

    System.exit(0);

    }

    }

    public static void main(String[] args)
    {


    Evaluate_6_1 wAveObject = new Evaluate_6();

    }
    }

    error codes:
    MOD6A.java:205: error: <identifier> expected
    one = Double.parseDouble(oneTF.getText());
    ^
    MOD6A.java:207: error: <identifier> expected
    wone = Double.parseDouble(woneTF.getText());
    ^
    MOD6A.java:209: error: <identifier> expected
    two = Double.parseDouble(twoTF.getText());
    ^
    MOD6A.java:211: error: <identifier> expected
    wtwo = Double.parseDouble(wtwoTF.getText());
    ^
    MOD6A.java:213: error: <identifier> expected
    three = Double.parseDouble(threeTF.getText());
    ^
    MOD6A.java:215: error: <identifier> expected
    wthree = Double.parseDouble(wthreeTF.getText());
    ^
    MOD6A.java:217: error: <identifier> expected
    four = Double.parseDouble(fourTF.getText());
    ^
    MOD6A.java:219: error: <identifier> expected
    wfour = Double.parseDouble(wfourTF.getText());
    ^
    MOD6A.java:221: error: <identifier> expected
    ave = (one * wone + two * wtwo + three * wthree
    ^
    MOD6A.java:225: error: <identifier> expected
    averageTF.setText(""+ twoDigits.format(ave));
    ^
    MOD6A.java:225: error: illegal start of type
    averageTF.setText(""+ twoDigits.format(ave));
    ^
    MOD6A.java:225: error: ')' expected
    averageTF.setText(""+ twoDigits.format(ave));
    ^
    MOD6A.java:225: error: ';' expected
    averageTF.setText(""+ twoDigits.format(ave));
    ^
    MOD6A.java:225: error: illegal start of type
    averageTF.setText(""+ twoDigits.format(ave));
    ^
    MOD6A.java:225: error: <identifier> expected
    averageTF.setText(""+ twoDigits.format(ave));
    ^
    MOD6A.java:225: error: ';' expected
    averageTF.setText(""+ twoDigits.format(ave));
    ^
    MOD6A.java:244: error: class, interface, or enum expected
    public static void main(String[] args)
    ^
    MOD6A.java:250: error: class, interface, or enum expected
    }
    ^
    18 errors


    Any and all help is welcome. Hope to complete by Sunday

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Need some help.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Many of the errors are because the statements need to be inside of a method.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    May 2016
    Location
    Brazil
    Posts
    16
    Rep Power
    0

    Default Re: Need some help.

    Also the identifier expected is the type of the variable, lacking in your code for a proper declaration.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •