/** A general driver program that uses a deck of shuffled cards. */ public class Driver { public static void main(String [] args) { // Create a shuffled deck of cards. Show all 52 cards so we can // see that they are shuffled correctly, and also to check that // we are dealing correctly later. (In a real game of course we would // not reveal all the cards like this.) Deck d = new Deck(); System.out.println("Here are all the cards:"); System.out.println(d); // Now that the cards have been shuffled, the game would continue // from here. Let's deal 5 cards. Card [] c = new Card[5]; for (int i = 0; i < 5; ++i) { c[i] = new Card(d.getNextCard()); System.out.printf("Card # %d is the %s\n", i+1, c[i]); } // I made the choice when implementing Hand.java to make the // poker hand have 5 separate card objects instead of an array. // So, unfortunately, the Hand constructor expects 5 objects. Hand h = new Hand(c[0], c[1], c[2], c[3], c[4]); // The rest of the code is copied from the old poker program. // Maybe these if-else statements should have been implemented in Hand // as well. Note that we cannot use a switch statement for these // choices. if (h.isRoyalFlush()) System.out.printf("you have a royal flush!\n"); else if (h.isStraightFlush()) System.out.printf("you have a straight-flush!\n"); else if (h.isFourOfKind()) System.out.printf("you have a 4 of a kind!\n"); else if (h.isFullHouse()) System.out.printf("you have a full house!\n"); else if (h.isFlush()) System.out.printf("you have a flush\n"); else if (h.isStraight()) System.out.printf("you have a straight\n"); else if (h.isThreeOfKind()) System.out.printf("you have 3 of a kind!\n"); else if (h.isTwoPair()) System.out.printf("you have 2 pair\n"); else if (h.isOnePair()) System.out.printf("you have 1 pair\n"); else System.out.printf("you have something else\n"); } }