// We want to have the ability to sort by zip code, and then break // ties by using the enrolment. import java.util.Comparator; public class SchoolComparator implements Comparator { public int compare(Object a, Object b) { int zip1 = ((School)a).getZip(); int zip2 = ((School)b).getZip(); int enrol1 = ((School)a).getEnrol(); int enrol2 = ((School)b).getEnrol(); // The goal is to return a negative if a < b, // return 0 if a == b, and return a positive if a > b. // In our comparison here, we look at ZIP code first. if (zip1 < zip2) return -1; else if (zip1 > zip2) return 1; else { if (enrol1 < enrol2) return -1; else if (enrol1 > enrol2) return 1; else return 0; } } }