//Client to test the PokerHand class // 1) Construction 2) toString() 3) Hand types // //Sample Output (5,000,000 trials) // QH TH 8C 7S 5S NO PAIR........ 2505024 50.10048% // 7C 6H 3C 2C 2D ONE PAIR....... 2114231 42.28462% // 9C 9S 4H 4S 2S TWO PAIR....... 237133 4.74266% // KC 6C 4C 4D 4H THREE OF A KIND 105816 2.11632% // AC 5C 4C 3S 2D STRAIGHT....... 19452 0.38904% // AC KC 8C 6C 3C FLUSH.......... 9933 0.19866% // KH KS 4C 4D 4S FULL HOUSE..... 7125 0.1425% // 5D 3C 3D 3H 3S FOUR OF A KIND. 1200 0.024% // JD TD 9D 8D 7D STRAIGHT FLUSH. 79 0.00158% // AC KC QC JC TC ROYAL FLUSH.... 7 1.4E-4% // 5000000.0 // 3111868.0 // import java.util.ArrayList; public class TestPokerHand { public static void main(String[] args) { final int TRIALS = 5000000; final double[] PAY_OFF = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 25.0, 50.0, 250.0}; ArrayList hands = new ArrayList(); ArrayList types = new ArrayList(); ArrayList count = new ArrayList(); CardDeck deck = new CardDeck(); for (int trial = 1; trial <= TRIALS; trial++) { deck.shuffle(); PokerHand hand = new PokerHand(deck); String type = hand.getHandType(); //Change to the actual method name int index = types.indexOf(type); if (index == -1) { hands.add(hand); types.add(type); count.add(1); } else count.set(index, count.get(index) + 1); } double payOut = 0.0; int nbrCases = types.size(); for (int k = 0; k < nbrCases; k++) { int m = 0; for (int c = 1; c < types.size(); c++) if (count.get(c) > count.get(m)) m = c; payOut += count.get(m) * PAY_OFF[k]; PokerHand hand = hands.remove(m); String type = types.remove(m); int number = count.remove(m); double percent = number * 100.0 / TRIALS; System.out.println(hand + pad16(type) + number + " " + percent + "%" ); } System.out.println((double)TRIALS); System.out.println(payOut); } private static String pad16(String str) { str = " " + str; while (str.length() < 16) str += "."; return str + " "; } }