// CSE 143, Winter 2010, Marty Stepp // A TA object represents one teaching assistant. // We made this class Comparable so that it can be stored in a priority queue. public class TA implements Comparable { private String name; private int experience; // 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; } // Compares this TA to the given other TA, returning -1 if I am "less" // than other, 0 if we are equal, 1 if I am "greater". Compares by TA // experience and then by name. public int compareTo(TA other) { int comp = experience - other.getExperience(); if (comp != 0) { return comp; } else { return name.compareTo(other.getName()); } } // 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)"; } }