public class Country implements Comparable
1: /**
2: A country with a name and area.
3: */
4: public class Country implements Comparable<Country>
5: {
6: /**
7: Constructs a country.
8: @param aName the name of the country
9: @param anArea the area of the country
10: */
11: public Country(String aName, double anArea)
12: {
13: name = aName;
14: area = anArea;
15: }
17: /**
18: Gets the name of the country.
19: @return the name
20: */
21: public String getName()
22: {
23: return name;
24: }
26: /**
27: Gets the area of the country.
28: @return the area
29: */
30: public double getArea()
31: {
32: return area;
33: }
36: /**
37: Compares two countries by area.
38: @param other the other country
39: @return a negative number if this country has a smaller
40: area than otherCountry, 0 if the areas are the same,
41: a positive number otherwise
42: */
43: public int compareTo(Country other)
44: {
45: if (area < other.area) return -1;
46: if (area > other.area) return 1;
47: return 0;
48: }
50: private String name;
51: private double area;
52: }