A teacher has 6 students who have taken 3 tests. The teacher uses the following
ID: 674776 • Letter: A
Question
A teacher has 6 students who have taken 3 tests. The teacher uses the following grading scale to assign a
letter grade to a student, based on the average of his or her 3 test scores.
Test Score Range Letter Grade
A= 90-100
b= 80-89
c=70-79
d=60-69
f=0-59
Create a class called Grades (java file called Grades.java) with the (exact) following fields and methods (these names and caps exactly):
1) Names An array of strings or ArrayList object to hold the 6 students’ names
2) LetterGrades An array of six characters to hold the six students’ letter grades
3) Test1Scores An array of doubles to hold each student’s Test 1 scores
4) Test2Scores An array of doubles to hold each student’s Test 2 scores
5) Test3Scores An array of doubles to hold each student’s Test 3 scores
6) EnterData Allow the user to input (in the console) the 6 students’ name, test 1 score, test 2 score, ands test 3 scores. The code should validate the score (only between 0 and 100) and ask again for the wrong values until the correct value is entered.
7) GetNames Outputs the student names (one student per line)
8) GetName Outputs a student’s name, student number given as an argument
9) GetTestScores Outputs a student’s test scores, student number given as an argument
10) GetTestScore Outputs a student’s test score, student number given as an argument, targeted test given as the second argument
11) GetAverageScore Outputs a student’s test score average (for the 3 tests), student number given as an argument
12) GetLetterGrades Outputs the students’ letter grades
13) GetLetterGrade Outputs a student’s letter grades, student number given as an argument
14) GetClassAverage Outputs the class average: the average of the 6 students’ test score average. Extra Credit.
15) GetTopGrade Outputs the top grade: the maximum/largest test score average from all 6 students. Extra Credit.
You are going to lose points if you do not name the class, the fields, or methods as requested. Demonstrate the class in a program/project called [YourName]-Assignment7 (replace [YourName] with your actual name) in the same project as the Grades.java. You will need to add the class Grades to the project and add your code to the project class main method. The program should allow the user to enter each student’s name and his or her 3 test scores and store them in a Grades object. The program should use the values from the Grades object to display in a table format each student’s name, average test score, and letter grade (one row per student). If you did any of the 2 extra credit methods, use the GetClassAverage and/or GetTopGrade methods to output the class average and the top score.
Explanation / Answer
The code for [Yourname]-Assignment7 class is:
class Assignment7
{
public static void main(String[] args)
{
Grades exam = new Grades();
exam.EnterData();
for(int i = 1; i <= 6; i++)
{
System.out.println(exam.GetName(i)+" "+exam.GetAverageScore(i)+" "+exam.GetLetterGrade(i));
}
exam.GetClassAverage();
exam.GetTopGrade();
}
}
The code for Grades.java is:
import java.util.Scanner;
class Grades
{
String[] Names = new String[6];
char[] LetterGrades = new char[6];
double[] Test1Scores = new double[6];
double[] Test2Scores = new double[6];
double[] Test3Scores = new double[6];
void EnterData()
{
Scanner sc=new Scanner(System.in);
for(int i = 0; i < 6; i++)
{
System.out.print("Enter the name of student "+(i+1)+": ");
Names[i] = sc.next();
do
{
System.out.print("Enter the score for Test 1: ");
Test1Scores[i] = sc.nextDouble();
}while(Test1Scores[i] < 0 || Test1Scores[i] > 100);
do
{
System.out.print("Enter the score for Test 2: ");
Test2Scores[i] = sc.nextDouble();
}while(Test2Scores[i] < 0 || Test2Scores[i] > 100);
do
{
System.out.print("Enter the score for Test 3: ");
Test3Scores[i] = sc.nextDouble();
}while(Test3Scores[i] < 0 || Test3Scores[i] > 100);
System.out.println("Testscores: "+Test1Scores[i]+" "+Test2Scores[i]+" "+Test3Scores[i]);
}
}
void GetNames()
{
for(int i = 0; i < 6; i++)
System.out.println((i+1)+". "+GetName(i+1));
}
String GetName(int studNumber)
{
return (Names[studNumber-1]);
}
void GetTestScores(int studNumber)
{
System.out.println(GetTestScore(studNumber, 1)+" ");
System.out.println(GetTestScore(studNumber, 2)+" ");
System.out.println(GetTestScore(studNumber, 3)+" ");
}
double GetTestScore(int studNumber, int testNumber)
{
if(testNumber == 1)
return (Test1Scores[studNumber-1]);
else if(testNumber == 2)
return (Test2Scores[studNumber-1]);
else if(testNumber == 3)
return (Test3Scores[studNumber-1]);
return 0;
}
double GetAverageScore(int studNumber)
{
double avg = (Test1Scores[studNumber-1] + Test2Scores[studNumber-1] + Test3Scores[studNumber-1]) / 3;
//System.out.println("The average scores of student "+studNumber+" is: "+avg);
return avg;
}
void GetLetterGrades()
{
for(int i = 1; i <= 6; i++)
{
System.out.println("The letter grade of student "+(i)+" is: "+GetLetterGrade(i));
}
}
char GetLetterGrade(int studNumber)
{
double sum = Test1Scores[studNumber-1] + Test2Scores[studNumber-1] + Test3Scores[studNumber-1];
char letterGrade;
if(sum / 3 >= 90)
letterGrade = 'A';
else if(sum / 3 >= 80)
letterGrade = 'B';
else if(sum / 3 >= 70)
letterGrade = 'C';
else if(sum / 3 >= 60)
letterGrade = 'D';
else
letterGrade = 'F';
return letterGrade;
}
void GetClassAverage()
{
double sum = 0.0;
for(int i = 0; i < 6; i++)
for(int j = 0; j < 3; j++)
sum += GetTestScore(i+1, j+1);
System.out.println("The average of the class is: "+ sum / 18);
}
void GetTopGrade()
{
char letterGrade;
double top = GetAverageScore(1);
for(int i = 2; i <= 6; i++)
if(GetAverageScore(i) > top)
top = GetAverageScore(i);
if(top >= 90)
letterGrade = 'A';
else if(top >= 80)
letterGrade = 'B';
else if(top >= 70)
letterGrade = 'C';
else if(top >= 60)
letterGrade = 'D';
else
letterGrade = 'F';
System.out.println("The top score of the class is: "+letterGrade);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.