1 /**
2 A country with a name and area.
3 */
4 public class 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 hashCode()
39 {
40 int h1 = name.hashCode();
41 int h2 = new Double(area).hashCode();
42 final int HASH_MULTIPLIER = 29;
43 int h = HASH_MULTIPLIER * h1 + h2;
44 return h;
45 }
46
47 public boolean equals(Object otherObject)
48 {
49 Country other = (Country) otherObject;
50 return name.equals(other.name)
51 && area == other.area;
52 }
53
54 public String toString()
55 {
56 return getClass().getName() + "[name=" + name
57 + ",area=" + area + "]";
58 }
59 }