import java.util.*; /** * Project #8.6 * CS 2334, Section 001 * October 12, 2003 *

* This class models a state including the name of * the state and it's population. *

* @author unknown * @version 1.0 */ public class State implements Comparable { /** The name of the state. */ private String name; /** Population of the state. */ private int population; /** * Default constructor. */ public State() { } /** * This is the constructor for the class Student. It instantiates the class * with user supplied values. *

* @param name The name of the state. * @param population The population of the state. */ public State(String name, int population) { this.name = name; this.population = population; } /** * This method returns the name and population of the state * as a single string. *

* @return String representing the contents of this object. */ public String toString() { return name + ", pop (" + population + ")"; } /** * Returns the name of the state as a String. *

* @return The name of the state. */ public String getName() { return name; } /** * Returns the population of the state. *

* @return The population. */ public int getPopulation() { return population; } /** * Sets the name of the state. *

* @param newName New name for the state. */ public void setName(String newName) { name = newName; } /** * Sets the population of the state. *

* @param newPopulation New population for the state. */ void setPopulation(int newPopulation) { population = newPopulation; } /** * This method compares an instance of State with this instance of State to * see if they are equal or to determine their relationship. *

* @param obj The object we are comparing this instance * of Person with. * @return Returns 0 if the two instances are equal, -1 if * other is less than this instance, 1 if other is * greater than this instance. * @.pre obj is an insance of State. * @throws IllegalArgumentException Thrown if obj is not an * instance of State. */ public int compareTo(Object obj) { /* Check precondition. */ if( ! ( obj instanceof State ) ) { throw new IllegalArgumentException( "Argument not a State" ); } /* Cast obj to type State. */ State otherState = (State)obj; /* Call compareTo on the state name and return it's result. */ return name.compareTo(otherState.getName()); } }