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);
}
}