class Student implements Comparable, java.util.Comparator{ String name; String vorname; long matrikelNr; short alter; short fachbereich; Student (String n, String v, long m, short a, short f){ name = n; vorname = v; matrikelNr = m; alter = a; fachbereich = f; } boolean leq(Student s1, Student s2 ){ int i1 = s1.name.compareTo(s2.name); if (i1 < 0) return true; if (i1 == 0) return s1.vorname.compareTo(s2.vorname) <= 0; return false; } public int compareTo(Object o){ Student s = (Student) o; int i = name.compareTo(s.name); if (i != 0) return i; return vorname.compareTo(s.vorname); } public int compare(Object o1, Object o2){ Student s = (Student) o1; return s.compareTo(o2); } public String toString(){ return name+", " + vorname + " FB " + fachbereich; } } public class Test { public static void main(String args[]) { Student st1 = new Student("Maier", "Hanns", 4242424242L, (short) 22, (short) 12); Student st2 = new Student("Maier", "Hanns", 4242424242L, (short) 22, (short) 12); Student st3 = new Student("Maier", "Berti", 4242424242L, (short) 22, (short) 12); Student st4 = new Student("Mister", "Hanns", 4242424242L, (short) 22, (short) 12); System.out.println (st1.compare(st1, st2) +" "+ st1 + st2); System.out.println (st1.compare(st1, st3) +" "+ st1 + st3); System.out.println (st1.compare(st1, st4) +" "+ st1 + st4); System.out.println (st4.compare(st4, st3) +" "+ st4 + st3); } }