1 import java.util.HashSet;
2 import java.util.Set;
3
4 /**
5 A program that prints hash codes of coins.
6 */
7 public class CoinHashCodePrinter
8 {
9 public static void main(String[] args)
10 {
11 Coin coin1 = new Coin(0.25, "quarter");
12 Coin coin2 = new Coin(0.25, "quarter");
13 Coin coin3 = new Coin(0.05, "nickel");
14
15 System.out.println("hash code of coin1=" + coin1.hashCode());
16 System.out.println("hash code of coin2=" + coin2.hashCode());
17 System.out.println("hash code of coin3=" + coin3.hashCode());
18
19 Set<Coin> coins = new HashSet<Coin>();
20 coins.add(coin1);
21 coins.add(coin2);
22 coins.add(coin3);
23
24 for (Coin c : coins)
25 System.out.println(c);
26 }
27 }