      1  /**

      2     A country with a name and area.

      3  */

      4  public class Country implements Comparable<Country>

      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(Country other)

     39     {

     40        if (area < other.area) return -1;

     41        if (area > other.area) return 1;

     42        return 0;

     43     }

     44

     45     public String toString()

     46     {

     47        return getClass().getName() + "[name=" + name

     48           + ",area=" + area + "]";

     49     }

     50  }