    /* A simple implementation of the Comparable interface.
     * Students with higher marks come before those with lower marks.
     * Otherwise, the ordering for identical marks is alphabetical
     * on names.
     */
class Student implements Comparable {
    public Student(String name, int mark){
        this.name = name;
        this.mark  = mark;
    }

        // In comparing this Student to the given Object, it is necessary
        // to ensure that o is, indeed, a Student.
    public int compareTo(Object o) throws ClassCastException {
        if(o == null){
            // Student should come before null objects.
            // Return a token negative value.
            return -1;
        }
        else{
            // This could result in a ClassCastException, if o is
            // not a Student.
            Student s = (Student) o;
            // Compare marks first. Higher marks come first.
            // So we want a negative result if our mark is higher.
            int markDifference = s.getMark() - getMark();
            if(markDifference != 0){
                return markDifference;
            }
            else{
                // Marks are the same. Compare names.
                return getName().compareTo(s.getName());
            }
        }
    }

        // Return a String representation of the student name mark.
    public String toString(){
        return getName()+" "+getMark();
    }

    public int getMark(){
        return mark;
    }

    public String getName(){
        return name;
    }

    private final String name;
    private final int mark;
}
