This program is suppose to allow the user to enter a student's name and (4) scores via GUI, instead of Scanner class. The class is to use a String array for 5 names, an array of 5 characters to hold letter grades, and 5 arrays of four doubles for each test score.
PROBLEMS:
1) When compiling, I get error: cannot find symbol (twice) for LINE 27
2) I'm only able to enter 1 set of data: 1 student and 4 scores, instead of 5 sets. And, therefore, output is only for 1 student.
3) I need to input/display data via simple GUI.
Can anyone lend some assistance? It would be greatly appreciated.
import java.util.Scanner; // Needs changed to javax.swing.JOptionPane
public class GraBook
{
public static void main(String[] args)
{
final int STUDENTS = 5;// Number of students
final char LETTERS = 5; // Number of grades
final int TESTS = 4; // Number of tests
// Create an array to hold students names, grades & scores
char[] grades = new char[LETTERS];
String[] names = new String[5];
double[] score1 = new double[TESTS];
double[] score2 = new double[TESTS];
double[] score3 = new double[TESTS];
double[] score4 = new double[TESTS];
char grade;
Scanner input = new Scanner(System.in); //Replace w/GUI
// Get the names of each student
for (int index=0; index < names.length; index++)
{
System.out.println("Enter student's name: " +
(index + 1) + ": ");
String[index]= keyboard.nextString(); //Replace w/GUI code
// Get student scores
System.out.println("Insert 4 test scores:");
double[] scores ={input.nextDouble(), input.nextDouble(), input.nextDouble(), input.nextDouble()};
// Average 4 test scores:
double average = 0;
for (int i = 0; i < scores.length; i++)
{
average += scores[i];
}
average /= scores.length;
if (average >= 90)
grade = 'A';
else if (average >= 80)
grade = 'B';
else if (average >= 70)
grade = 'C';
else if (average >= 60)
grade = 'D';
else
grade = 'F';
System.out.println(names + " has a(n) " + grade + " with an average test score of " + average); // Replace w/GUI code
}
}
}