Please give an answer in Java. a. Write the definition of the class Tests such t
ID: 664548 • Letter: P
Question
Please give an answer in Java.
a. Write the definition of the class Tests such that an object of this class can store a student’s first name, last name, five test scores, average tests score, and grade. (Use an array to store the test scores.) Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString must return test data (including student’s name, five test scores, average, and grade) as a string.
b. Write a program to calculate students’ average test scores and the grade. You may assume the following input data:
Use an array of objects of the class Tests (designed in part (a)) to store each student’s data. The program should output data as close as possible to the following form:
First Name Last Name Jack Lisa Andy Ravi Bonny Danny Samantha Kennedy Robin Sheila Kiran Johnson Aniston Cooper Gupta Blair Clark Testl Test2 Test3 Test4 Test5 Average Grade 85.00 83.DD 77.00 91.00 76.00 82.40 80.00 90.00 95.00 93.00 48.00 81.20 78.00 81.00 11.00 90.00 73.00 66.60 92.00 83.00 30.00 69,00 87.00 72.20 23.00 45.00 96.00 38.00 59.00 52.20 60.00 85.00 45.00 39.00 67.00 59.20 77.00 31.00 52.00 74.00 83.00 63.40 93.00 94.0089.00 77.00 97.00 90.00 79.0085.00 28.00 93.00 82.00 3.40 85.00 72.D0 49.00 75.00 63.00 68.80 Bronson Sunny Smith 2 Class average 70.94Explanation / Answer
package com.tutai;
public class Tests {
private String firstName;
private String lastName;
private int[] testScores;
private double avgTestScore;
private char grade;
public Tests(){
firstName="";
lastName="";
testScores=new int[5];
avgTestScore=0.0;
grade=' ';
}
public Tests(String firstName,String lastName,int[] testScores){
this.firstName=firstName;
this.lastName=lastName;
this.testScores=testScores;
avgTestScore=0.0;
grade=' ';
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int[] getTestScores() {
return testScores;
}
public void setTestScores(int[] testScores) {
this.testScores = testScores;
}
public void calculateTestAverage(){
double sum=0.0;
for(int i=0;i<5;i++){
sum+=testScores[i];
}
avgTestScore=sum/5;
}
public double returnTestAverage(){
return avgTestScore;
}
public void calculateGrade(){
if(avgTestScore>=90){
grade='A';
}else if(avgTestScore>=80&&avgTestScore<90){
grade='B';
}else if(avgTestScore>=70&&avgTestScore<80){
grade='C';
}else if(avgTestScore>=60&&avgTestScore<70){
grade='D';
}else{
grade='F';
}
}
public char returnGrade(){
return grade;
}
public void modifyTestScore(int position,int score){
testScores[position]=score;
}
public String toString(){
String output="";
output+=firstName+" "+lastName+" ";
for(int i=0;i<5;i++){
output+=testScores[i]+" ";
}
output+=avgTestScore+" "+grade;
return output;
}
public static void main(String[] args){
Tests[] t=new Tests[10];
t[0]=new Tests("Jack","Johnson",new int[]{85,83,77,91,76});
t[1]=new Tests("Lisa","Aniston",new int[]{80,90,95,93,48});
t[2]=new Tests("Andy","Cooper",new int[]{78,81,11,90,73});
t[3]=new Tests("Ravi","Gupta",new int[]{92,83,30,69,87});
t[4]=new Tests("Bonny","Blair",new int[]{23,45,96,38,59});
t[5]=new Tests("Danny","Clark",new int[]{60,85,45,39,67});
t[6]=new Tests("Samantha","Kennedy",new int[]{77,31,52,74,83});
t[7]=new Tests("Robin","Bronson",new int[]{93,94,89,77,97});
t[8]=new Tests("Sheila","Sunny",new int[]{79,85,28,93,82});
t[9]=new Tests("Kiran","Smith",new int[]{85,72,49,75,63});
double classSum=0.0,classAverage=0.0;
System.out.println("First_Name Last_name Test1 Test2 Test3 Test4 Test5 Average Grade");
for(int i=0;i<10;i++){
t[i].calculateTestAverage();
t[i].calculateGrade();
classSum+=t[i].returnTestAverage();
System.out.println(t[i].toString());
}
classAverage=classSum/10;
System.out.println("");
System.out.println("Class Average = "+classAverage);
}
}