001package horstmann.ch04_sort2;
002/**
003   A country with a name and area.
004 */
005public class Country implements Comparable<Country>
006{
007        /**
008      Constructs a country.
009      @param aName the name of the country
010      @param anArea the area of the country
011         */
012        public Country(String aName, double anArea)
013        {
014                name = aName;
015                area = anArea;
016        }
017
018        /**
019      Gets the name of the country.
020      @return the name
021         */
022        public String getName()
023        {
024                return name;
025        }
026
027        /**
028      Gets the area of the country.
029      @return the area
030         */
031        public double getArea()
032        {
033                return area;
034        }
035
036
037        /**
038      Compares two countries by area.
039      @param other the other country
040      @return a negative number if this country has a smaller
041      area than otherCountry, 0 if the areas are the same,
042      a positive number otherwise
043         */
044        public int compareTo(Country other)
045        {
046                if (area < other.area) return -1;
047                if (area > other.area) return 1;
048                return 0;
049        }
050
051        private String name;
052        private double area;
053}