Our next few programming assignments will deal with the game of Poker. In this assignment we will ignore all aspects of betting, bluffing, chips, or any other decisions on the part of each player this will deal solely with representing playing cards, shuffling the deck, dealing cards into hands, and ranking hands.

Part I Infrastructure

Write a class, PokerCard, to represent a card in a game of Poker. A card has rank and suit, where rank is (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10 (T), Jack (J), Queen (Q), King (K), Ace (A)) and suit is (Clubs - C, Diamonds - D, Hearts - H, Spades - S). Note that Ace can be either value 1 or 14, depending on what the player wants. PokerCard objects have a natural order based on rank (suit is ignored), with Ace largest and 2 lowest, so you should implement the Comparable< PokerCard> interface.

  • PokerCard.toString() should print as a two character string, rank then suit. E.g., 2C for two of clubs, TS for ten of spades, QH for queen of hearts, etc.
  • he class should also include a constructor that takes a String, e.g. PokerCard card = new PokerCard(2C);

Write a class, PokerHand, to represent a collection of 5 PokerCard objects. Define an enumeration, PokerHandCategory, with the following values: HIGH_CARD, PAIR, TWO_PAIR, THREE_OF_A_KIND, STRAIGHT, FLUSH, FULL_HOUSE, FOUR_OF_A_KIND, STRAIGHT_FLUSH. PokerHands are ordered first by category, then by individual card ranks; even the lowest hand that qualifies in a certain category defeats all hands in lower categories. All hands that do not contain a pair or some higher ranking category are considered to be in the HIGH_CARD category. For more details, please see http://en.wikipedia.org/wiki/List_of_poker_hands. Note the following details (all should be listed in Wikipedia page):

  • 7 7 5 3 2 > 6 6 A 3 2 (a pair of 7s is better than a pair of 6s)
  • 7 7 A 3 2 > 7 7 Q 3 2 (both players have a pair of 7s, but an Ace is higher than a Queen)
  • Q Q Q 2 2 > J J J A A (both players have a full house, but three queens is better than three jacks)
  • K Q J T 9 > T 9 8 7 6 (both players have a straight, but the King is higher than the ten).
  • T 9 8 7 6 > 5 4 3 2 A (if the ace is used as a one, it is not considered a high card).

The PokerHand should implement Comparable, as well as the following methods:

  • void addCard(PokerCard card)
  • String toString() should print each card, separated by a space, followed by the category. For example, 7H 7S AH 4H 2C, HIGH_CARD

Write a class, PokerDeck, which contains one of each of the 52 possible PokerCard cards (no duplicates). This class needs to have the following methods:

class PokerDeck {
void shuffle(); // you may use Collections.shuffle
PokerCard draw(); // remove a card from the “top” of the deck
void draw(PokerHand targetHand); // remove a card from the “top” of the deck, add it to targetHand
}

It is highly encouraged that you write unit tests for PokerCard, PokerHand, and PokerDeck.

Part II SimplePokerGame

Write a console based program to demonstrate a very simple version of Poker for 8 players. Your program should:

1) Create a PokerDeck, and shuffle it.
2) Create 8 PokerHands
3) Deal one card to each hand at a time until every hand has 5 cards.
4) Determine which “player” (or players if there is a tie) has the best hand rank, and display the
player numbers.
5) Display, in rank order, each player and that player’s hand.

Example output:

We have 1 winning player(s): Player 2
Player 2, 3D 4S QD KD KH, PAIR, [K, Q, 4, 3]
Player 8, 2S 7H 7S 8C JH, PAIR, [7, J, 8, 2]
Player 4, 6H 6S TD QS AS, PAIR, [6, A, Q, T]
Player 7, 4D 4H 6C KS AH, PAIR, [4, A, K, 6]
Player 1, 2C 3C 3H 9H JD, PAIR, [3, J, 9, 2]
Player 6, 2H JC QC KC AD, HIGH_CARD, [A, K, Q, J, 2]
Player 5, 2D 8H 9C TH QH, HIGH_CARD, [Q, T, 9, 8, 2]
Player 3, 3S 5C 9S TC JS, HIGH_CARD, [J, T, 9, 5, 3]
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.