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