01: import javax.swing.JOptionPane;
02: 
03: /**
04:    This class tests the Purse class by prompting the
05:    user to add coins into a purse and printing the 
06:    purse contents, sorted by coin value.
07: */
08: public class PurseTest
09: {
10:    public static void main(String[] args)
11:    {
12:       double NICKEL_VALUE = 0.05;
13:       double DIME_VALUE = 0.1;
14:       double QUARTER_VALUE = 0.25;
15: 
16:       Purse myPurse = new Purse();
17: 
18:       boolean done = false;
19:       while (!done)
20:       {
21:          String input 
22:             = JOptionPane.showInputDialog("Enter coin name or Cancel");
23:          if (input == null) 
24:             done = true;
25:          else
26:          {
27:             double value = 0;
28:             if (input.equals("nickel"))
29:                value = NICKEL_VALUE;
30:             else if (input.equals("dime"))
31:                value = DIME_VALUE;
32:             else if (input.equals("quarter"))
33:                value = QUARTER_VALUE;
34:             if (value != 0)
35:             {
36:                Coin c = new Coin(value, input);
37:                myPurse.add(c);
38:                System.out.println("The contents of the purse is "
39:                   + myPurse);
40:             }
41:          }
42:       }
43:       System.exit(0);
44:    }
45: }