A teacher has three students who have taken two tests The te
A teacher has three students who have taken two tests. The teacher uses the following scale to assign a letter grade to a student, based on the average of his or her two test scores.
Test Score Letter Grade
90 - 100                  A
 80 - 89                    B
 70 - 79                    C
 60 - 69                    D
 0 - 59                      F
Write a program that uses an array of string objects to hold the three student names, an array of three characters to hold the three students\' letter grades, and three arrays of two doubles to hold each student\'s set of test scores.
The program should allow the user to enter each student\'s name and his or her two test scores. It should then calculate and display each student\'s average test score and a letter grade based on the average.
Store the number of students and scores in global named constants STUDENTS and SCORES. Use the constants to declare your arrays and when you process the arrays. Your arrays must NOT be global. Your program must include a function called inputData which accepts an element of the name array (passed by reference) and the cooresponding array of test scores as arguments and initializes both the name and the test score array.
Input Validation: Do not accept test scores less than 0 or greater than 100.
Solution
public class StudentInfo
{
private static class StudentEntry{
String name;
double grade0, grade1, grade2, grade3;
public char getLetterGrade()
{
double averageGrade=(grade0+grade1+grade2+grade3)/4;
if(averageGrade>=90 && averageGrade<=100)
return \'A\';
else if(averageGrade>=80 && averageGrade<=89)
return \'B\';
else if(averageGrade>=70 && averageGrade<=79)
return \'C\';
else if(averageGrade>=60 && averageGrade<=69)
return \'D\';
else if(averageGrade>=0 && averageGrade<=59)
return \'F\';
else
return \'r\';
}
}
private StudentEntry[] data;
private int dataCount;
public StudentInfo()
{
data=new StudentEntry[1];
dataCount=0;
}
private int find(String name)
{
for(int i=0; i<dataCount; i++)
{
if(data[i].name.equals(name))
return i;
}
return -1;
}
public double getAverageGrade(String name){
int position=find(name);
if(position==-1)
return -1;
else
return (data[position].grade0+data[position].grade1+data[position].grade2+data[position].grade3)/4;
}
public void putGrades(String name, double g0, double g1, double g2, double g3){
if(name==null || g0==-1 || g1==-1 || g2==-1 || g3==-1)
throw new IllegalArgumentException(\"Name and grades cannot be empty\");
if((g0<0||g0>100)&&(g1<0||g1>100)&&(g2<0||g2>100)&&(g3<0||g3>100))
throw new IllegalArgumentException(\"Grades must be in the range from 0 to 100\");
int i=find(name);
if(i>=0)
data[i].grade0=g0;
data[i].grade1=g1;
data[i].grade2=g2;
data[i].grade3=g3; }
else{
if(dataCount==data.length)
{
StudentEntry[] newData=new StudentEntry[2*data.length];
System.arraycopy(newData, 0, data, 0, dataCount);
data=newData;
}
]StudentEntry newEntry=new StudentEntry();
newEntry.name=name;
newEntry.grade0=g0;
newEntry.grade1=g1;
newEntry.grade2=g2;
newEntry.grade3=g3;
data[dataCount]=newEntry;
dataCount++;
}
}
}



