Hey Guys,

I've never used JLabel and JText Area before and this specific project requires it. I'm trying to create something that allows entry of student name, id and 2 grades. Then get the average of the 2 tests and show the letter grade equivalent. I'm getting error messages that says "[COLOR=red]illegal start of expression[/COLOR]" on the [COLOR=blue]public static void towards the bottom of coding[/COLOR]. do you have any suggestions on how to run this properly??? Thanks!

import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
import javax.swing.border.*;
public class StudentGrades extends JFrame 
{
   // JPanel for user inputs
   private JPanel inputGradeJPanel;

   // JLabel and JTextField for student name
   private JLabel studentNameJLabel;
   private JTextField studentNameJTextField;

   // JLabel and JTextField for student ID
   private JLabel studentIDJLabel;
   private JTextField studentIDJTextField;

   // JLabel and JTextField for midterm score
   private JLabel midtermJLabel;
   private JTextField finalsJTextField;
   // JLabel and JTextField for finals score
   private JLabel finalsJLabel;
   private JTextField finalsJTextField;
   // JButton to calculate student grade
   private JButton submitGradesJButton;
   // JLabel and JTextArea to display student grade
   private JLabel displayJLabel;
   private JTextArea displayJTextArea;
   // JButton to show student letter grade
   private JButton submitGradesJButton;
   // JLabel and JTextArea to display student letter grade
   private JLabel displayJLabel;
   private JTextArea displayJTextArea;
   // initialize number of students to zero
   private int studentCount = 0;
   // constants 
   private final int number_of_tests = 2;
   private final int maximum_students = 10;
   private final int midterm_test = 0;
   private final int final_test = 1;

   // one-dimensional array to store student names
   private String studentNames[] = new String[ maximum_students ];
   // two-dimensional array to store student grades
   private int studentGrades[][] = 
      new int[ maximum_students ][ number_of_tests ];
   // DecimalFormat for two digits of precision
   private DecimalFormat twoDigits = new DecimalFormat( "0.00" );
   // no-argument constructor
   public StudentGrades()
   {
      createUserInterface();
   }
   // create and position GUI components; register event handlers
   private void createUserInterface()
   {      
      Container contentPane = getContentPane();
      contentPane.setLayout( null );
      // set up inputGradeJPanel
      inputGradeJPanel = new JPanel();
      inputGradeJPanel.setBounds( 16, 16, 208, 218 );
      inputGradeJPanel.setBorder(
         new TitledBorder( "Input Grade" ) );
      inputGradeJPanel.setLayout( null );
      contentPane.add( inputGradeJPanel );

      // set up studentNameJLabel
      studentNameJLabel = new JLabel();
      studentNameJLabel.setBounds( 8, 32, 90, 23 );
      studentNameJLabel.setText( "Student Name:" );
      inputGradeJPanel.add( studentNameJLabel );
      // set up studentNameJTextField
      studentNameJTextField = new JTextField();
      studentNameJTextField.setBounds( 104, 32, 88, 21 );
      studentNameJTextField.setHorizontalAlignment(
         JTextField.RIGHT );
      inputGradeJPanel.add( studentNameJTextField );

      // set up studentIDJLabel
      studentNameJLabel = new JLabel();
      studentNameJLabel.setBounds( 8, 32, 90, 23 );
      studentNameJLabel.setText( "Student ID:" );
      inputGradeJPanel.add( studentNameJLabel );
      // set up studentIDJTextField
      studentNameJTextField = new JTextField();
      studentNameJTextField.setBounds( 104, 32, 88, 21 );
      studentNameJTextField.setHorizontalAlignment(
         JTextField.RIGHT );
      inputGradeJPanel.add( studentIDJTextField );

      // set up midtermJLabel
      test1JLabel = new JLabel();
      test1JLabel.setBounds( 8, 74, 60, 23 );
      test1JLabel.setText( "Midterm:" );
      inputGradeJPanel.add( test1JLabel );
      // set up midtermJTextField
      test1JTextField = new JTextField();
      test1JTextField.setBounds( 136, 74, 56, 21 );
      test1JTextField.setHorizontalAlignment( JTextField.RIGHT );
      inputGradeJPanel.add( test1JTextField );
      // set up finalJLabel
      test2JLabel = new JLabel();
      test2JLabel.setBounds( 8, 74, 60, 23 );
      test2JLabel.setText( "Final:" );
      inputGradeJPanel.add( test2JLabel );

      // set up finalJTextField
      test1JTextField = new JTextField();
      test1JTextField.setBounds( 136, 74, 56, 21 );
      test1JTextField.setHorizontalAlignment( JTextField.RIGHT );
      inputGradeJPanel.add( test1JTextField );
      // set up submitGradesJButton
      submitGradesJButton = new JButton();
      submitGradesJButton.setBounds( 72, 182, 120, 24 );
      submitGradesJButton.setText( "Submit Grades" );
      inputGradeJPanel.add( submitGradesJButton );
      submitGradesJButton.addActionListener(

         new ActionListener() // anonymous inner class
         {
            // event handler called when submitGradesJButton 
            // is clicked
            public void actionPerformed( ActionEvent event )
            {
               submitGradesJButtonActionPerformed( event );
            }
         } // end anonymous inner class
      ); // end call to addActionListener
      // set up displayJLabel
      displayJLabel = new JLabel();
      displayJLabel.setBounds( 240, 16, 150, 23 );
      displayJLabel.setText( "Grade:" );
      contentPane.add( displayJLabel );

      // set up displayJTextArea
      displayJTextArea = new JTextArea();
      displayJTextArea.setBounds( 240, 48, 402, 184 );
      displayJTextArea.setEditable( false );
      contentPane.add( displayJTextArea );

      // set properties of application's window
      setTitle( "Student Grades for CIS190 Online Programming" ); // set title bar string
      setSize( 670, 308 );          // set window size
      setVisible( true );           // display window
   } // end method createUserInterface
   // convert a number to a letter grade
   private String convertToLetterGrade( double grade )
   {
      if ( grade >= 90 )
      {
         return "A";
      }
      else if ( grade >= 80 )
      {
         return "B";
      }
      else if ( grade >= 70 )
      {
         return "C";
      }
      else if ( grade >= 60 )
      {
         return "D";
      }
      else
      {
         return "F";
      }

   } // end method convertToLetterGrade
   // calculate and display the student and class average
   private void submitGradesJButtonActionPerformed(
      ActionEvent event )
   {
      // get user input
      String nameOfStudent = studentNameJTextField.getText();
      int test1 = Integer.parseInt( test1JTextField.getText() );
      int test2 = Integer.parseInt( test2JTextField.getText() );

      // add user input to arrays
      studentNames[ studentCount ] = nameOfStudent;
      studentID [studentID ] = studentID;
      studentGrades[ studentCount ][ FIRST_TEST ] = test1;
      studentGrades[ studentCount ][ SECOND_TEST ] = test2;     

      // clear other JTextFields for new data
      studentNameJTextField.setText( "" );
      studentIDJTextField.setText( "" );
      test1JTextField.setText( "" );
      test2JTextField.setText( "" );
   } // end method submitGradesJButtonActionPerformed
   // display student grades and averages as numbers
   private void displayNumericGrades()
   {
      // add a header to displayJTextArea
      displayJTextArea.setText( 
         "Name\tID\tMidterm 2\tAverage\t Grade\n" );
      int studentTotal = 0; // store the student's total grades

      for ( int student = 0; student < studentCount; student++ )
      {
         // display student names
         displayJTextArea.append( studentNames[ student ] + "\t" );
         studentTotal = 0; // initialize the student's total grades

         for ( int test = 0; test < NUMBER_OF_TESTS; test++ )
         {
         { // display student ID
         displayJTextArea.append( studentID[ ID ] + "\t" );
         studentTotal = 0; // store the student's ID

         for ( int test = 0; test < NUMBER_OF_TESTS; test++ )
         {
            // append each test grade to displayJTextArea
            displayJTextArea.append(
               studentGrades[ student ][ test ] + "\t" );
            // add the test grade to the student's total
            studentTotal += studentGrades[ student ][ test ];
         } // end inner for
         // calculate the student average and display it
         double studentAverage = 
            ( double ) studentTotal / NUMBER_OF_TESTS;
         displayJTextArea.append( 
            twoDigits.format( studentAverage ) + "\n" );

      // add a header to displayJTextArea
      displayJTextArea.setText( 
         "Name\tID\tMidterm 2\tAverage\t Grade\n" );
      int studentTotal = 0; // store the student's total grades

      for ( int student = 0; student < studentCount; student++ )
      {
         // display student names
         displayJTextArea.append( studentNames[ student ] + "\t" );
         studentTotal = 0; // initialize the student's total grades
         for ( int test = 0; test < NUMBER_OF_TESTS; test++ )
         {
            // append each test grade to displayJTextArea
            displayJTextArea.append( convertToLetterGrade( 
               studentGrades[ student ][ test ] ) + "\t" );
            // add the test grade to the student's total
            studentTotal += studentGrades[ student ][ test ];
         } // end inner for
         // calculate the student average and display it
         double studentAverage = 
            ( double ) studentTotal / NUMBER_OF_TESTS;
         displayJTextArea.append( 
            convertToLetterGrade( studentAverage ) + "\n" );
      } // end outer for

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

   } // end method main
} // end class StudentsGrade2

Well, illegal expression normally means that you have not closed a ( ) pair, a { } pair, or have forgotten a ;. Judging by your comments I am assuming you have not closed the { } pair that defines the method that contains your "outer for" loop.

} // end outer for
}
}
}
}

You need to provide four } at the end.
Hey why such silly qs are here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.