1.11M Members

can someone help me complete this program.. its giving me a head ache...

 
0
 
import java.awt.event.ActionListener;
import javax.swing.JFrame;

//This Java Program determines the weighted average
//of four test scores.

//import statements for the needed packages

public class Assign1 extends JFrame
{

    //declare JLabel variables as reference to label components
    //declare JTextField variables as reference to input/output text boxes
    //declare JButton variables as reference to command buttons
    //declare button handlers to handle click events of command buttons
    //declare constants to hold the size of your windows

    public Assign1()
    {
            // Create eight labels

            //Create four textfields

            //create Calculate Button

            //Create Exit Button

            //Set the title of the window

            //Get the container

            //Set the layout
            //Place the components in the pane

            //set the size of the window and display it
    }

    // class which defines the action when the Calculate button is pressed
    private class CalculateButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            //place your code here
        }
    }

    // class which defines the action when the Exit button is pressed
    private class ExitButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            //place your code here
        }
    }

    // main method which constructs this particular class
    public static void main(String[] args)
    {
            //place your code here
    }
}
 
0
 

Code tags:

[code=JAVA] // paste code here

[/code]

Code looks terrible without them.

This looks like a cut and paste of the assignment specification that someone gave you. What seems to be the problem?

 
0
 

i dont know what to use. I need to be able to create a table. where i can input my scores and the weight or percentage of one quiz. Then the out put should be the final grade or the average score

 
0
 

The code gives you a guide. Start filling it in. Call the constructor from main. Do lines 12 - 35 and set up the GUI and display it. That gives you a start and requires no Action Listeners and no calculations and no need for any input. Ignore line 15 for now. You need to do them anyway, so might as well start there. It's just building the GUI.

import java.awt.event.ActionListener;
import javax.swing.JFrame;

//This Java Program determines the weighted average
//of four test scores.

//import statements for the needed packages

public class Assign1 extends JFrame
{

//declare JLabel variables as reference to label components
//declare JTextField variables as reference to input/output text boxes
//declare JButton variables as reference to command buttons
//declare button handlers to handle click events of command buttons
//declare constants to hold the size of your windows

public Assign1()
{
// Create eight labels

//Create four textfields

//create Calculate Button

//Create Exit Button

//Set the title of the window

//Get the container

//Set the layout
//Place the components in the pane

//set the size of the window and display it
}

// class which defines the action when the Calculate button is pressed
private class CalculateButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//place your code here
}
}

// class which defines the action when the Exit button is pressed
private class ExitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//place your code here
}
}

// main method which constructs this particular class
public static void main(String[] args)
{
//place your code here
}
}
 
0
 

Does anyone have any ideas how to limit or require the sum of the weights to equal 1.00? My program compiles, runs, and functions, but I can't figure out how to regulate the weight column so that it must add up to 1.00.
This is what I have
`

/*
    Page 381 
    Desing a GUI program to find the weighted average of four test scores.
    The four test scores and their perspective weights are given in the 
    following format:
    testscore1 weight1
*/

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class pg381 extends JFrame

{
    private JLabel labelTest1, labelTest2, labelTest3, labelTest4, labelWeight1, labelWeight2, labelWeight3, labelWeight4, labelAverage;
    private JTextField textTest1, textTest2, textTest3, textTest4, textWeight1, textWeight2, textWeight3, textWeight4, textAverage;
    private JButton buttonCalculate, buttonExit;
    private CalculateHandler cHandler;
    private ExitHandler eHandler;
    private static final int WIDTH = 400;
    private static final int HEIGHT = 300;

    public pg381()
    {
       //create the labels
      labelTest1 = new JLabel("Enter test score1: ", SwingConstants.RIGHT);
       labelTest2 = new JLabel("Enter test score2: ", SwingConstants.RIGHT);
       labelTest3 = new JLabel("Enter test score3: ", SwingConstants.RIGHT);
       labelTest4 = new JLabel("Enter test score4: ", SwingConstants.RIGHT);

      labelWeight1 = new JLabel("Enter the weight of test score1: ", SwingConstants.RIGHT);
      labelWeight2 = new JLabel("Enter the weight of test score1: ", SwingConstants.RIGHT);
      labelWeight3 = new JLabel("Enter the weight of test score1: ", SwingConstants.RIGHT);
      labelWeight4 = new JLabel("Enter the weight of test score1: ", SwingConstants.RIGHT);
      labelAverage = new JLabel("The weighted average is: ", SwingConstants.RIGHT);



       //create the text fields
       textTest1 = new JTextField(10);
      textWeight1 = new JTextField(10);
       textTest2 = new JTextField(10);
      textWeight2 = new JTextField(10);
       textTest3 = new JTextField(10);
      textWeight3 = new JTextField(10);
       textTest4 = new JTextField(10);
       textWeight4 = new JTextField(10);
       textAverage = new JTextField(10);

       // create the calculate button
       buttonCalculate = new JButton("Calculate");
       cHandler = new CalculateHandler();
       buttonCalculate.addActionListener(cHandler);


       // create the exit button
       buttonExit = new JButton("Exit");
       eHandler = new ExitHandler();
       buttonExit.addActionListener(eHandler);


       //set the form title
       setTitle("The weighted average is: ");


        // set the container (form) layout
        Container pane = getContentPane();
        pane.setLayout(new GridLayout(10,5));

       //place components in the pane
       pane.add(labelTest1);
      pane.add(textTest1);
      pane.add(labelWeight1);
      pane.add(textWeight1);


      pane.add(labelTest2);
      pane.add(textTest2);
      pane.add(labelWeight2);
      pane.add(textWeight2);

      pane.add(labelTest3);
      pane.add(textTest3);
      pane.add(labelWeight3);
      pane.add(textWeight3);


      pane.add(labelTest4);
      pane.add(textTest4);
      pane.add(labelWeight4);
      pane.add(textWeight4);

      pane.add(labelAverage);
       pane.add(textAverage);
       pane.add(buttonCalculate);
       pane.add(buttonExit);    

      // set dimensions and display the form
      setSize(WIDTH, HEIGHT);
      setVisible(true);
       setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
   // define the button handler logic
    private class CalculateHandler implements ActionListener
   {
       public void actionPerformed(ActionEvent e)
        {
         // declare the variables needed for the calculation
           double test1, test2, test3, test4, weight1, weight2, weight3, weight4, average1, average2, average3, average4, Totalaverage;

           // convert the users input to doubles
           test1 = Double.parseDouble(textTest1.getText());
         test2 = Double.parseDouble(textTest2.getText());
         test3 = Double.parseDouble(textTest3.getText());
         test4 = Double.parseDouble(textTest4.getText());
         weight1 = Double.parseDouble(textWeight1.getText());
         weight2 = Double.parseDouble(textWeight2.getText());     
         weight3 = Double.parseDouble(textWeight3.getText());        
         weight4 = Double.parseDouble(textWeight4.getText());


         // calculations
         average1 = test1 * weight1;
         average2 = test2 * weight2;
         average3 = test3 * weight3;
         average4 = test4 * weight4;
         Totalaverage = average1 + average2 + average3 + average4;

         //
         if (test1>100) 

         else popup("Score must be between 0-100");
         {
         if (test1<0) 
         else popup
         }
         if sum of weight1 + weight2 + weight3 + weight4 not equal 1.00 then popup

         //// put the results into the on screen boxes
         textAverage.setText("" + Totalaverage);

        }
    }


    // exit handler
    private class ExitHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {

            // all done, exit will force the screen to close
            System.exit(0);
        }
    }


    // main program to display the form we built
    public static void main(String[] args)
    {
        // creating a new instance invokes the construcor that displays the screen
        pg381 screen = new pg381(); 

    }
}   

`

 
0
 

This is a three year old thread.
DaniWeb Member Rules include:
"Do not hijack old threads by posting a new question as a reply to an old one"
http://www.daniweb.com/community/rules
Please start your own new thread for your question

 
0
 

Sorry I am new to this site. I am still learning how all of this works, thanks for the info though. I will do that next time.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article