Results 1 to 2 of 2
  1. #1
    xduh9 is offline adoi
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default need help about class average,do while statement..please

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

    public class ClassAverage1 extends JFrame
    {

    private JLabel gradeListJLabel;
    private JTextArea gradeListJTextArea;


    private JButton ContinueJButton;


    private JButton getGradesJButton;



    private JButton averageJButton;


    private JLabel classAverageJLabel;
    private JTextField classAverageJTextField;


    private int total = 0;

    public ClassAverage1()
    {
    createUserInterface();
    }


    private void createUserInterface()
    {

    Container contentPane = getContentPane();


    contentPane.setLayout( null );


    gradeListJLabel = new JLabel();
    gradeListJLabel.setBounds( 16, 8, 70, 23 );
    gradeListJLabel.setText( "Grade list:" );
    contentPane.add( gradeListJLabel );




    gradeListJTextArea = new JTextArea();
    gradeListJTextArea.setBounds( 16, 32, 88, 180 );
    contentPane.add( gradeListJTextArea );



    getGradesJButton = new JButton();
    getGradesJButton.setBounds( 128, 50, 100, 26 );
    getGradesJButton.setText( "Get Grades" );
    contentPane.add( getGradesJButton );
    getGradesJButton.addActionListener(



    new ActionListener()
    {

    public void actionPerformed( ActionEvent event )
    {
    getGradesJButtonActionPerformed( event );
    }

    }

    );

    averageJButton = new JButton();
    averageJButton.setBounds( 128, 90, 100, 26 );
    averageJButton.setText( "Average" );
    averageJButton.setEnabled( false );
    contentPane.add( averageJButton );
    averageJButton.addActionListener(

    new ActionListener()
    {

    public void actionPerformed( ActionEvent event )
    {
    averageJButtonActionPerformed( event );
    }

    }

    );


    classAverageJLabel = new JLabel();
    classAverageJLabel.setBounds( 128, 132, 90, 23 );
    classAverageJLabel.setText( "Class average:" );
    contentPane.add( classAverageJLabel );


    classAverageJTextField = new JTextField();
    classAverageJTextField.setBounds( 128, 156, 100, 21 );
    classAverageJTextField.setEditable( false );
    classAverageJTextField.setHorizontalAlignment(
    JTextField.CENTER );
    contentPane.add( classAverageJTextField );


    setTitle( "Class Average" );
    setSize( 250, 250 );
    setVisible( true );

    }


    private void getGradesJButtonActionPerformed( ActionEvent event )
    {
    total = 0;
    int counter = 1;
    String input;
    int grade;

    gradeListJTextArea.setText( "" );
    classAverageJTextField.setText( "" );

    do
    {

    input = JOptionPane.showInputDialog( null, "Enter Grade" );
    grade = Integer.parseInt( input );


    gradeListJTextArea.append( grade + "\n" );
    total += grade;
    counter++;
    }
    while ( counter <= 7 );

    averageJButton.setEnabled( true );
    averageJButton.requestFocusInWindow();

    }

    private void averageJButtonActionPerformed( ActionEvent event )
    {
    double average = ( double ) total / 7;
    classAverageJTextField.setText( String.valueOf( average ) );

    }


    public static void main( String[] args )
    {
    ClassAverage1 application = new ClassAverage1();
    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    }

    }


    =please help me how to insert do,while condition which is if i continue to give another grades.
    thank you!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: need help about class average,do while statement..please

    Come on now. This is your second identical question, and the first one was never answered because it was a terrible question -- likewise for this which is identical.

    First at least make a good faith attempt to solve this on your own before dumping the assignment here in this forum. Then ask about specific problems with your existing attempted implementation.

Similar Threads

  1. SQL statement working in one class but not another
    By Dcalladi in forum New To Java
    Replies: 4
    Last Post: 11-11-2011, 02:35 AM
  2. Java, if statement calling class
    By illinit in forum New To Java
    Replies: 5
    Last Post: 08-25-2011, 09:04 PM
  3. Problem understanding class statement.
    By martijnburger in forum New To Java
    Replies: 3
    Last Post: 07-22-2011, 12:07 AM
  4. Urgent/ Help with average method in created class
    By johnjacob in forum New To Java
    Replies: 12
    Last Post: 12-07-2010, 03:47 AM

Posting Permissions

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