// definition of class 'City', with comments as per javadoc

/**
 * A <code>City</code> object defines a city with a
 * name/pop pair where 'name' is the name of the city
 * as a <code>String</code>
 * and 'pop' is the city's population as an <code>int</code>.
 *
 * @version 1.0
 * @author Scott MacKenzie
 */

public class City implements Comparable
{
   /** The city name. */
   private String name;
   /** The city population. */
   private int pop;

   /**
    * Creates a new city with the specified name and
    * population.
    */
   public City(String name, int pop)
   {
      this.name = name;
      this.pop = pop;
   }

   /**
    * Creates a new city with the specified name and
    * an initial population of 0.  
    */
   public City(String name)
   {
      this.name = name;
      this.pop = 0;
   }

   /** Returns the city's name. */
   public String getName()         { return name;  }

   /** Returns the city's population. */
   public int getPop()             { return pop;   }

   /** Set the city's population to the specified value. */
   public void setPop(int newPop)  { pop = newPop; }

   /** Returns a string representing the city. */ 
   public String toString()
   {
      return "City [name: " + name + " pop: " + pop + "]";
   }

   /** Tests the <code>City</code> class.
    *
    * <p>To test the <code>City</code> class, execute
    * as follows:<p>
    * <p>
    * <p>&nbsp;&nbsp;&nbsp;<code>PROMPT>java City
    * test_name test_pop</code><p>
    * <p>
    * where <code>test_name</code> is the name of a city, and
    * <code>test_pop</code> is the city's population.  The test
    * will instantiate a <code>City</code> object and then
    * convert it to a string using the <code>toString()</code>
    * method.
    * The string is sent it to
    * stdout and will appear as follows:<p>
    * <p>
    * <p>&nbsp;&nbsp;&nbsp;<code>City [name: test_name pop:
    * test_pop]</code>
    */
   public static void main(String[] args)
   {
      if (args.length != 2)
      {
         System.out.println("Usage: java City name pop");
         return;
      }
      String testName = args[0];
      int testPop = Integer.parseInt(args[1]);
      City c = new City(testName, testPop);
      System.out.println(c);
   }

   /** Implements comparable.  Allows two city objects
    * to be compared.  Comparison is lexicographical
    * based on the <code>name</code> field, much the
    * same as the <code>compareTo()</code> in the
    * <code>String</code> class.
    */
   public int compareTo(Object o)
   {
      return (this.name).compareTo(((City)o).name);
   }
}

