I'm working on the following assignment and could use some help:
A teacher has five students who have taken four tests.The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores:
Test Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
0-59 F
Write a class that uses a string array or an ArrayList object to hold the five students' names, an array of five characters to hold the five students' letter grades, and five arrays of four doubles each to hold each student's set of test scores. The class should have methods that return a specific student's name, average test score, and a
letter grade based on the average. Demonstrate the class in a program that allows the user to enter each student's name and his or her four test scores. It should then display each student's average test score and letter grade. Input validation: Do not accpet test scores less than zero or greater than 100.
Here are my two files of code that I have so far:
public class Grades
{ // Begin public class Grades
private double[] testScores; // Variable that will ref an array of test scores
/**
Constructor
@param scoreArray An array of test scores
*/
public Grades(double[] scoreArray)
{ // Assign the array argument to the testScores field
testScores = scoreArray;
}
/**
getAverage method
@return The average of the test scores
*/
public double getAverage()
{ // Begin public double getAverage()
double total = 0; // To hold the score total
double average; // To hold the average
// If array contains less than 4 test scores, display error message and set
// average to 0
if (testScores.length < 4)
{ // Begin if statement
System.out.println("Error: You must have atleast " +
"four test scores!");
average = 0;
} // End if statement
else
{ // Begin else statement
// Calculate total of the scores
for (double score : testScores)
total += score;
// Get the average of the scores
average = total / (testScores.length - 1);
} // End else statement
// Return the average of the test scores
return average;
} // End public double getAverage()
} // End public class Grades
import java.text.DecimalFormat; // Needed to format test score average
import javax.swing.JOptionPane; // Needed for showInputDialog & showMessageDialog
public class calcAverage
{ // Begin public class calcAverage
static DecimalFormat formatter = new DecimalFormat("###.##"); // Global decimal formatter
public static void main(String[] args)
{ // Begin public static void main(String[] args)
int numScores; // To hold the number of scores
String studNames; // To hold the names of the students
// Get the number of test scores
System.out.println("How many test scores do you have? ");
numScores = keyboard.nextInt();
// Get the names of the students
System.out.println("Please enter the student's name ");
// Create an array to hold the test scores
double[] scores = new double[numScores];
// Create an array to hold the names of the students
String[] names = new String[studNames];
// Get the test scores and store them in the scores array
for (int index = 0; index < numScores; index++)
{ // Begin for loop
System.out.println("Enter score" +
(index + 1) + ": ");
scores[index] = keyboard.nextDouble();
} // End for loop
// Create a Grades object, passing the scores array as an argument to the constructor
Grades myGrades = new Grades(scores);
// Display the average of the test scores
System.out.println("Your test score average is " +
myGrades.getAverage());
} // End public static void main(String[] args)
} // End public class calcAverage
If someone could please give me some direction as to where I go from here, I would appreciate it.