import java.util.*;classPerson {protectedString firstName;protectedString lastName;protected intidNumber;//Constructor
Person(String firstName, String lastName, intidentification){this.firstName =firstName;this.lastName =lastName;this.idNumber =identification;
}//Print person data
public voidprintPerson(){
System.out.println("Name: " + lastName + ", " +firstName+ "\nID: " +idNumber);
}
}class Student extendsPerson{private int[] testScores;/** Class Constructor
*
* @param firstName - A string denoting the Person's first name.
* @param lastName - A string denoting the Person's last name.
* @param id - An integer denoting the Person's ID number.
* @param scores - An array of integers denoting the Person's test scores.*/
//Write your constructor here
Student(String firstName, String lastName, int id, int[] scores){
super(); //隐藏会执行的默认构造器super(firstName, lastName, id); //因为少了父类自定义构造器初始化,所以会报错this.firstName =firstName;this.lastName =lastName;this.idNumber =id;this.testScores =scores;
}/** Method Name: calculate
* @return A character denoting the grade.*/
//Write your method here
public charcalculate(){int num =testScores.length;int s = 0;for(intscore : testScores) {
s= s +score;
}
s= s/num;char grade = '-';if(s>=90&&s<=100){
grade= 'O';
}else if(s>=80&&s<90){
grade= 'E';
}else if(s>=70&&s<80){
grade= 'A';
}else if(s>=55&&s<70){
grade= 'P';
}else if(s>=40&&s<55){
grade= 'D';
}else if(s<40){
grade= 'T';
}returngrade;
}
}classSolution {public static voidmain(String[] args) {
Scanner scan= newScanner(System.in);
String firstName=scan.next();
String lastName=scan.next();int id =scan.nextInt();int numScores =scan.nextInt();int[] testScores = new int[numScores];for(int i = 0; i < numScores; i++){
testScores[i]=scan.nextInt();
}
scan.close();
Student s= newStudent(firstName, lastName, id, testScores);
s.printPerson();
System.out.println("Grade: " +s.calculate());
}
}