• + 0 comments

    import java.util.Scanner;

    class Person { String firstName; String lastName; int id;

    public Person(String firstName, String lastName, int id) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.id = id;
    }
    

    }

    class Student extends Person { private int[] testScores;

    public Student(String firstName, String lastName, int id, int[] testScores) {
        super(firstName, lastName, id);
        this.testScores = testScores;
    }
    
    public char calculate() {
        int sum = 0;
        for (int score : testScores) {
            sum += score;
        }
        int avg = sum / testScores.length;
    
        if (avg >= 90) return 'O';
        else if (avg >= 80) return 'E';
        else if (avg >= 70) return 'A';
        else if (avg >= 55) return 'P';
        else if (avg >= 40) return 'D';
        else return 'T';
    }
    

    }

    public class Solution { public static void main(String[] args) { Scanner scn = new Scanner(System.in); String firstName = scn.next(); String lastName = scn.next(); int id = scn.nextInt(); int numScores = scn.nextInt(); int[] scores = new int[numScores];

        for (int i = 0; i < numScores; i++) {
            scores[i] = scn.nextInt();
        }
    
        Student std = new Student(firstName, lastName, id, scores);
        System.out.println("Name: "+lastName+", "+firstName);
        System.out.println("ID: "+id);
        System.out.println("Grade: "+std.calculate());
        scn.close();
    }
    

    }