// A TA object represents one teaching assistant. // This class implements the Comparable interface so that // TAs can be ordered and put into a priority queue. public class TA implements Comparable { private String name; private int experience; // # of quarters served as a TA // Returns an integer representing the relative ordering // between this object and the given other TA object. // < 0 -> i come "before" the other object // > 0 -> i come "after" the other object // 0 -> i am "equal to" the other object public int compareTo(TA otherTA) { if (this.experience != otherTA.experience) { // if we have a different number of quarters of TAing experience, // compare us that way (the "subtraction trick") return this.experience - otherTA.experience; } else { // if we have the same number of quarters of TAing experience, // compare us by our names instead (the "delegation trick") return this.name.compareTo(otherTA.name); } } // Constructs a new TA with given name and number of quarters' experience. // Throws IllegalArgumentException if name is null or experience is negative. public TA(String name, int experience) { if (name == null || experience < 0) { throw new IllegalArgumentException(); } this.name = name; this.experience = experience; } // Returns the TA's name. public String getName() { return name; } // Returns the TA's quarters of experience. public int getExperience() { return experience; } // Returns string with name and number of quarters, such as "Kim (5q)". public String toString() { return name + " (" + experience + "q)"; } }