01: /**
02:    A coin with a monetary value.
03: */
04: public class Coin
05: {
06:    /**
07:       Constructs a coin.
08:       @param aValue the monetary value of the coin.
09:       @param aName the name of the coin
10:    */
11:    public Coin(double aValue, String aName) 
12:    { 
13:       value = aValue; 
14:       name = aName;
15:    }
16: 
17:    /**
18:       Gets the coin value.
19:       @return the value
20:    */
21:    public double getValue() 
22:    {
23:       return value;
24:    }
25: 
26:    /**
27:       Gets the coin name.
28:       @return the name
29:    */
30:    public String getName() 
31:    {
32:       return name;
33:    }
34: 
35:    public boolean equals(Object otherObject)
36:    {
37:       if (otherObject == null) return false;
38:       if (getClass() != otherObject.getClass()) return false;
39:       Coin other = (Coin) otherObject;
40:       return value == other.value && name.equals(other.name);
41:    }
42: 
43:    public int hashCode()
44:    {
45:       int h1 = name.hashCode();
46:       int h2 = new Double(value).hashCode();
47:       final int HASH_MULTIPLIER = 29;
48:       int h = HASH_MULTIPLIER * h1 + h2;
49:       return h;
50:    }
51: 
52:    public String toString()
53:    {
54:       return "Coin[value=" + value + ",name=" + name + "]";
55:    }
56: 
57:    private double value;
58:    private String name;
59: }