X712: Write A Comparator 2

For this question, we will be sorting Person objects. Here is the Person class so you’ll know what you have available:

public class Person{



    private int age;
    private String name;
    private String grade;

    public Person(int a, String n, String gr) {
        age = a;
        name = n;
        grade = gr;
    }


    public int getAge() {
        return age;
    }


    public String getGrade() {
        return grade;
    }

}

In this code, the String grade will ONLY ever be “excellent”, “good”, “satisfactory”, “unsatisfactory”, or “poor”. “Excellent” is the best possible grade, “good” the second best, and so on until the worst grade, “poor”. Below is the start of a comparator to compare Person objects by grade. Your task will be to finish the comparator.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.