I need to make this program GradeCalculator.java, and I can't figure out what is wrong with it. I'm really struggling, could someone please help! Thanks!!

In the GradeCalculator.java program the user clicks the Enter button.
The first input is a JOptionPane that asks the user, “Number of score to be entered?”
scoreAmount = JOptionPane.showInputDialog("Number of scores to be entered?"); numberOfScores = Integer.parseInt(scoreAmount);
When the OK button is clicked another JOptionPane opens asking the user to enter a score (integer) and the JOptionPane will be repeated depending in the value entered for the “Number of score to be entered” (for loop).
The values entered are stored in an accumulator: accumulatorVariable += scoreVariable
The += adds the current value of the scoreVariable to the value already stored in the accumulatorVariable. When the last number is entered (end of for loop) a method calls calculateAverageScore();
The calculateAverageScore method determines the letter score using the ‘if block’:
averageScore > 89, letter score is A
averageScore > 79, letter score is B
averageScore > 69, letter score is C
averageScore > 64, letter score is D
when the averageScore values is below 64 the default letter score is an F

//import statements
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;

public class GradeCalculator extends JFrame 
{

   //declaration section
   Color white = new Color(255, 255, 255);
   Color black = new Color(0, 0, 0);

   JLabel gradeLetterJLabel;
   JTextField gradeLetterJTextField;

   JTextField clickEnterJLabel;

   JButton enterJButton;
   JButton clearJButton;
   JButton closeJButton;

   int numberOfScores;
   int scoreAmount;
   int averageScore;
   String gradeLetterLetter;

      public GradeCalculator()
      {
         createUserInterface();
      }
      public void createUserInterface()
      {
      Container contentPane = getContentPane();
      contentPane.setBackground(white);
      contentPane.setLayout(null);

        gradeLetterJLabel = new JLabel();
        gradeLetterJLabel.setBounds(50, 50, 120, 20);
        gradeLetterJLabel.setFont(new Font("Default", Font.PLAIN, 12));
        gradeLetterJLabel.setText("Grade");
        gradeLetterJLabel.setForeground(black);
        gradeLetterJLabel.setHorizontalAlignment(JLabel.RIGHT);
        contentPane.add(gradeLetterJLabel);

        gradeLetterJTextField = new JTextField();
        gradeLetterJTextField.setBounds(200, 50, 50, 20);
        gradeLetterJTextField.setFont(new Font("Default", Font.PLAIN, 12));
        gradeLetterJTextField.setHorizontalAlignment(JTextField.CENTER);
        gradeLetterJTextField.setForeground(black);
        gradeLetterJTextField.setBackground(white);
        gradeLetterJTextField.setEditable(false);
        contentPane.add(gradeLetterJTextField);

        clickEnterJLabel.setBounds(50, 50, 120, 20);
        clickEnterJLabel.setFont(new Font("Default", Font.PLAIN, 12));
        clickEnterJLabel.setText("Click Enter To Start!");
        clickEnterJLabel.setForeground(black);
        clickEnterJLabel.setHorizontalAlignment(JLabel.CENTER);
        contentPane.add(clickEnterJLabel);

        enterJButton = new JButton();
        enterJButton.setBounds(25, 300, 100, 20);
        enterJButton.setFont(new Font("Default", Font.PLAIN, 12));
        enterJButton.setText("Enter");
        enterJButton.setForeground(black);
        enterJButton.setBackground(white);
        contentPane.add(enterJButton);
        enterJButton.addActionListener(

         new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    enterJButtonActionPerformed(event);
                }
            }
        );

        clearJButton = new JButton();
        clearJButton.setBounds(150, 300, 100, 20);
        clearJButton.setFont(new Font("Default", Font.PLAIN, 12));
        clearJButton.setText("Clear");
        clearJButton.setForeground(black);
        clearJButton.setBackground(white);
        contentPane.add(clearJButton);
        clearJButton.addActionListener(


         new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    clearJButtonActionPerformed(event);
                }
            }
        );

        closeJButton = new JButton();
        closeJButton.setBounds(275, 300, 100, 20);
        closeJButton.setFont(new Font("Default", Font.PLAIN, 12));
        closeJButton.setText("Close");
        closeJButton.setForeground(black);
        closeJButton.setBackground(white);
        contentPane.add(closeJButton);
        closeJButton.addActionListener(

         new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    closeJButtonActionPerformed(event);
                }
            }
        );

      setTitle("Grade Calculator");
      setSize(400, 400);
      setVisible(true);
      }

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

      public void enterJButtonActionPerformed(ActionEvent event)
      {
         //number of scores
         scoreAmount = JOptionPane.showInputDialog("Number of scores to be entered?"); 
         numberOfScores = Integer.parseInt(scoreAmount);

         button = new JButton("OK"); 
         JOptionPane.add(button); 
         button.addActionListener(this);
         button = new JButton("Cancel"); 
         JOptionPane.add(button); 
         button.addActionListener(this);
      }
      //FOR Loop for enter score box.  
         public void getAccumulatorVariable()
      {
         for (int numberOfScores; numberOfScores > 0; JOptionPane.showInputDialog("Enter Score")) {
            accumulatorVariable += scoreVariable;

         button = new JButton("OK"); 
         JOptionPane.add(button); 
         button.addActionListener(this);
         button = new JButton("Cancel"); 
         JOptionPane.add(button); 
         button.addActionListener(this);

      }

      //calculate average score
      public void calculateAverageScore()
      {
         averageScore = accumulatorVariable / numberofScores;
      }


      //find Grade Letter      
      public void calculateGrade()
      {

         if (averageScore > 89) 
         {
            gradeLetterJTextField.setText("A");    
         }

         if (averageScore > 79) 
         {
            gradeLetterJTextField.setText("B");
         }

         if (averageScore > 69) 
         {
            gradeLetterJTextField.setText("C"); 
         }

         if (averageScore > 64)
         {
            gradeLetterJTextField.setText("D");
         }

         if (averageScore <= 64)
         {
            gradeLetterJTextField.setText("F");
         }

      }

   public void clearJButtonActionPerformed(ActionEvent event)
   {
         gradeLetterJTextField.setText("");
         gradeLetterJTextField.requestFocusInWindow();
         ticketPriceJTextField.setText("");
         admissionJTextField.setText("");

   }
   public void closeJButtonActionPerformed(ActionEvent event)
   {
      System.exit(0);
   }

}

If you have a compiler or runtime error message post the complete message plus the actual code it refers to. If your code is giving an incorrect result explain what result you get and what the correct result should be.

it maybe cant be out for the loop, because you have

for (int numberOfScores; numberOfScores > 0; JOptionPane.showInputDialog("Enter Score")){
//...
}

this is an example
for(int numberOfScores; numberOfScores > 0; numberOfScores--)
here i use numberOfScores-- because this variable can be decreased for an compliant of the second condition (numberOfScores>0), then if numberOfScores value = 0, it finish the loop, or u need use an break sentence for out; then, i recomend that ur JOptionPane.showInputDialog("Enter Score")
will be declared in the segment for, because it doesn't store any value, only show a message.
maybe u can use ...

for(int numberOfScores; numberOfScores > 0; numberOfScores--){
int scoreTemp = IntegerParseInt(JOptionPane.showInputDialog("Enter Score"));
//... more of ur logic here 
}

is all, regards!

commented: Very helpful +15

I can't check to see if that solution worked, because I am also getting an error when compiling, starting at line 158

GradeCalculator.java:168: error: illegal start of expression
      public calculateAverageScore()
      ^
GradeCalculator.java:168: error: ';' expected
      public calculateAverageScore()
                                    ^
GradeCalculator.java:175: error: illegal start of expression
      public void calculateGrade()
      ^
GradeCalculator.java:175: error: illegal start of expression
      public void calculateGrade()
             ^
GradeCalculator.java:175: error: ';' expected
      public void calculateGrade()
                                ^
GradeCalculator.java:205: error: illegal start of expression
   public void clearJButtonActionPerformed(ActionEvent event)
   ^
GradeCalculator.java:205: error: illegal start of expression
   public void clearJButtonActionPerformed(ActionEvent event)
          ^
GradeCalculator.java:205: error: ';' expected
   public void clearJButtonActionPerformed(ActionEvent event)
                                          ^
GradeCalculator.java:205: error: ';' expected
   public void clearJButtonActionPerformed(ActionEvent event)
                                                            ^
GradeCalculator.java:213: error: illegal start of expression
   public void closeJButtonActionPerformed(ActionEvent event)
   ^
GradeCalculator.java:213: error: illegal start of expression
   public void closeJButtonActionPerformed(ActionEvent event)
          ^
GradeCalculator.java:213: error: ';' expected
   public void closeJButtonActionPerformed(ActionEvent event)
                                          ^
GradeCalculator.java:213: error: ';' expected
   public void closeJButtonActionPerformed(ActionEvent event)
                                                            ^
GradeCalculator.java:218: error: reached end of file while parsing
}

that problem is caused here:

public void getAccumulatorVariable()
      {
         for (int numberOfScores; numberOfScores > 0; JOptionPane.showInputDialog("Enter Score")) {
            accumulatorVariable += scoreVariable;
         button = new JButton("OK"); 
         JOptionPane.add(button); 
         button.addActionListener(this);
         button = new JButton("Cancel"); 
         JOptionPane.add(button); 
         button.addActionListener(this);
      }

you forget to put a closing bracket for your for loop

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.