package Lecture13; import java.util.*; public class Interface1 { public static void main(String[] args) { Student[] list= new Student[4]; list[0]= new Student("Mary", 6); list[1]= new Student("Joan", 4); list[2]= new Student("Anna", 8); list[3]= new Student("John", 2); Arrays.sort(list); for (int i= 0; i < list.length; i++) { Student s= list[i]; System.out.println(s.getName() + " " + s.getTerms()); } } } class Student implements Comparable { public Student(String n, int t) { name= n; terms= t; } public String getName() {return name; } public int getTerms() {return terms; } public int compareTo(Object b) { // Requerido por Comparable Student two= (Student) b; if (terms < two.terms) return -1; else if (terms > two.terms) return 1; else return 0; } private String name; private int terms; }