import java.util.*; public class PiggyBankClient { private static Random generator = new Random(); public static void main(String[] args) { //Create an empty PiggyBank PiggyBank stash = new PiggyBank(); //Drop several US coins of various types into the PiggyBank int numberOfCoins = generator.nextInt(41) + 80; //80 .. 120 for (int k = 1; k <= numberOfCoins; k++) stash.drop( randomUSCoin() ); //Display and empty the PiggyBank System.out.println(stash + "\nTotal $" + stash.empty()); } //Returns a randomly selected US Coin //In a large number of calls, the % returns of each different coin type approximates // 30% PENNIES, 25% NICKLES, 20% DIMES, 20% QUARTERS, 4% HALF-DOLLARS, 1% DOLLARS private static US_Coin randomUSCoin() { int key = generator.nextInt(100); if (key < 30) return US_Coin.PENNY; else if (key < 55) return US_Coin.NICKLE; else if (key < 75) return US_Coin.DIME; else if (key < 95) return US_Coin.QUARTER; else if (key < 99) return US_Coin.HALF_DOLLAR; else return US_Coin.DOLLAR; } }