public class Student implements Comparable<Student> {
private final String name;
private final double cGPA;
public Student(String name, double cGPA) {
this.name = name;
this.cGPA = cGPA;
}
public String getName() {
return name;
}
public double getCGPA() {
return cGPA;
}
// Natural order: ascending by GPA (descending can be done with reverseOrder() in the driver)
@Override
public int compareTo(Student other) {
return Double.compare(this.cGPA, other.cGPA);
}
@Override
public String toString() {
return String.format("Name=%s; Cumulative GPA=%.2f", name, cGPA);
}
}