Public class TestList
{
public static void main(String args[])
{
ArrayList students = new ArrayList();
students. Add(new Student("Kara", 11, 3. 8));
students. Add(new Student("Fernando", 12, 4. 1));
students. Add(new Student("Anita", 10, 2. 7));
}
}
public class Student
{
private String name;
private int grade;
private double gpa;
public Student(String n, int g, double ave)
{
name = n;
grade = g;
gpa = ave;
}
public Student(String n)
{
name = n;
grade = gpa = 0;
}
// other methods not shown including equals & compareTo (based on name) as well as toString
}
Question : Write a compareTo method for the Student class. The method should return the difference in the names