Hello all,

this is just another student level program and I need some help with the final bit.

This a program that gets input from a user and outputs teh student name, average grade, all scores highest score, etc.

But I am having trouble outputing the scores (which are in an array), formatting the JOptionPane so that all the output is in one dialog box.

I get these errors:

Program4.java:103: cannot find symbol
symbol  : variable i
location: class Program4
"\nScores: " + studentScores[i] + " ",
                             ^
Program4.java:102: cannot find symbol
symbol  : method showMessageDialog(<nulltype>,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog(null, "Student Name: " + studentName,   
           ^
2 errors

Here is the code:

import javax.swing.JOptionPane;                                     // Use the JOption for I/O

public class Program4                                           // Declare program name
{
   public static void main(String[] args)                       // Declare Main method
   {
      String inputString,
             outputString = "";


   // Set variables

   String studentName = "";      // Student name 
   int[] studentScores = new int[10];    //  Students studentScores (input)
   int   best = 0;                // Student's best score
   int   studentHighScore = 0;  // Students highest score
   char  studentLetter = ' ';     // Students letter studentLetter
   int   count = 0;        // Counts number of scores input
    double average = 0;    // Student's average of the studentScores
    double total = 0;

   // Prompt user to enter in the students name
   studentName = JOptionPane.showInputDialog("Please enter student's name:");

    System.out.println(studentName);

   //Prompt user to input studentScores

      for (int i = 0; i < studentScores.length; i++)
    {
      inputString = JOptionPane.showInputDialog("Please enter a score:");
        studentScores[i] = Integer.parseInt(inputString);

        count++;

      if (studentScores[i] > best)
         best = studentScores[i];
        else if (studentScores[i] < 0)
        {
          i = 11;
          count--;
       }

    }

  for (int j = 0;j < count; j++)
  {
    total += studentScores[j];
  }

  average = total / (count);
  System.out.println(average);



       for (int i = 0; i < studentScores.length; i++)          // Assign and display studentLetters
   {
      if ( (average >= 96) && (average <= 100) )
        studentLetter = 'A';
      else if ( (average >= 92) && (average <= 96) )
        studentLetter = 'B';
      else if ( (average >= 88) && (average <= 92) )
        studentLetter = 'C';
      else if ( (average >= 84) && (average <= 88) )
        studentLetter = 'D';
      else
        studentLetter = 'F';
    }

System.out.println(studentLetter);

for (int k = 0; k < count; k++)
{
  if (studentHighScore < studentScores[k])
    studentHighScore = studentScores[k];
}

System.out.println(studentHighScore);

int startScan, index, minIndex, minValue;

for (startScan = 0; startScan < count; startScan++)
      {
         minIndex = startScan;
         minValue = studentScores[startScan];
         for(index = startScan + 1; index < count; index++)
         {
            if (studentScores[index] < minValue)
            {
               minValue = studentScores[index];
               minIndex = index;
            }
         }
         studentScores[minIndex] = studentScores[startScan];
         studentScores[startScan] = minValue;
      }

for (int i = 0; i < count; i++)
  System.out.print(studentScores[i] + " ");

// Declare and initialize output

JOptionPane.showMessageDialog(null, "Student Name: " + studentName,   
"\nScores: " + studentScores[i] + " ",
"\nAverage: " + average,
"\nHigh Score: " + studentHighScore,
"\nLetter Grade: " + studentLetter);  


      }
}

Hello all,
for (int i = 0; i < count; i++)
System.out.print(studentScores + " ");

// Declare and initialize output

JOptionPane.showMessageDialog(null, "Student Name: " + studentName,
"\nScores: " + studentScores + " ",
"\nAverage: " + average,
"\nHigh Score: " + studentHighScore,
"\nLetter Grade: " + studentLetter);
}
}

The variable i is declare at: for (int i = 0; i < count; i++). But since you don't have "{" and "}" the for loop only repeats: System.out.print(studentScores + " ") ;
The rest are outside of the for-loop hence the i variable is not declared nad cannot be seen.

As for the second, make sure if you are using the right syntaxe for the method JOptionPane

Alright thank you! That solved the first issue.

So, I've been looking at the syntax for the JOptionPane and I don't really see anything wrong.

I tried using this instead and it doesn't change the error message.

JOptionPane.showMessageDialog(null, ("Student Name: " + studentName),
("\nScores: " + studentScores + " "),
("\nAverage: " + average),
("\nHigh Score: " + studentHighScore),
("\nLetter Grade: " + studentLetter));

Anyone have any suggestions?

Are you sure showMessageDialog takes arguments (null, String, String, String, String, String)?

I think you need to check your argument types.

this:

JOptionPane.showMessageDialog(null, ("Student Name: " + studentName),
("\nScores: " + studentScores + " "),
("\nAverage: " + average),
("\nHigh Score: " + studentHighScore),
("\nLetter Grade: " + studentLetter));

showMessageDialog(null,string,string,string,string,string)

should be showMessageDialog(null,string text,string title,int,icon) or much more simply showMessageDialog(null,string text) i believe that you are trying to concatenate the strings with the comma, but the comma should be replaced with a plus (+) sign if you do that it should be fine

change ur for loop like this and add new Frame() in ur JOptionPane

for (int i = 0; i < count; i++)
{
System.out.print(studentScores[i] + " ");

// Declare and initialize output

JOptionPane.showMessageDialog(new Frame(), "Student Name: " + studentName +
"\nScores: " + studentScores[i] + " " +
"\nAverage: " + average +
"\nHigh Score: " + studentHighScore +
"\nLetter Grade: " + studentLetter);
}

null is an accepted argument for the frame, null centers the dialog on screen its the commas instead of pluses that was causing the problem

change ur for loop like this and add new Frame() in ur JOptionPane

for (int i = 0; i < count; i++)
{
System.out.print(studentScores[i] + " ");

// Declare and initialize output

JOptionPane.showMessageDialog(new Frame(), "Student Name: " + studentName +
"\nScores: " + studentScores[i] + " " +
"\nAverage: " + average +
"\nHigh Score: " + studentHighScore +
"\nLetter Grade: " + studentLetter);
}

sciwizeh is correct, null is the appropriate argument there. Passing "new Frame()" is absolutely useless.

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.