import java.util.Comparator; /** PersonComparator.java - How do we compare names of people? * Check the last names first. */ public class PersonComparator implements Comparator { public int compare(Object o1, Object o2) { Person p1 = (Person) o1; Person p2 = (Person) o2; String first1 = p1.getFirst(); String first2 = p2.getFirst(); String last1 = p1.getLast(); String last2 = p2.getLast(); if (last1.compareTo(last2) < 0) return -1; else if (last1.compareTo(last2) > 0) return 1; else { if (first1.compareTo(first2) < 0) return -1; else if (first1.compareTo(first2) > 0) return 1; else return 0; } } }