Country.java.html

  1  /**
  2     A country with a name and area.
  3  */
  4  public class Country implements Comparable
  5  {
  6     private String name;
  7     private double area;
  8  
  9     /**
 10        Constructs a country.
 11        @param aName the name of the country
 12        @param anArea the area of the country
 13     */
 14     public Country(String aName, double anArea) 
 15     { 
 16        name = aName;
 17        area = anArea; 
 18     }
 19  
 20     /**
 21        Gets the country name.
 22        @return the name
 23     */
 24     public String getName() 
 25     {
 26        return name;
 27     }
 28  
 29     /**
 30        Gets the area of the country.
 31        @return the area
 32     */
 33     public double getArea() 
 34     {
 35        return area;
 36     }
 37     
 38     public int compareTo(Object otherObject)
 39     {
 40        Country other = (Country) otherObject;
 41        if (area < other.area) { return -1; }
 42        else if (area == other.area) { return 0; }
 43        else { return 1; }
 44     }
 45     
 46     public String toString()
 47     {
 48        return getClass().getName() + "[name=" + name 
 49           + ",area=" + area + "]";
 50     }
 51  }