In a standard deck of 52 playing cards, each card is one of the following kinds: Ace (A), 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack (J), Queen (Q), and King (K). In the card game Poker, you can think of the Jack, Queen, and King as being like 11, 12, and 13, respectively. An Ace is special because it can be treated either as a 1 (called low) or as a 14 (called high), but not both.

Each card is also one of the following suits: Spades (S), Hearts (H), Clubs (C), or Diamonds (D). A deck contains exactly one card for each combination of kind and suit. For example, there are four Aces which can be written AS, AH, AC, and AD representing the Ace of Spades, Ace of Hearts, Ace of Clubs, and Ace of Diamonds respectively. There are also four twos (which can be written 2S, 2H, 2C, 2D), etc.

The card game Poker uses a standard deck of 52 playing cards. A player is dealt a hand consisting of five cards at random. The players hand is then scored into one of a number of categories. Please read the description of Poker hand categories at: https://en.wikipedia.org/wiki/List_of_poker_hand_categories

Note that the category Five of a kind does not apply to a standard deck of 52 playing cards. Also, note that a hand in the category High Card can be more precisely described using one of the following sub-categories determined by the highest ranking card in the hand. In a High Card hand, any Ace is always treated as high, i.e., as a 14, and thus has the highest rank.

1. Seven high
2. Eight high
3. Nine high
4. Ten high
5. Jack high
6. Queen high
7. King high
8. Ace high

If more than one category applies to a hand, then only the highest ranking applicable category is used to describe the hand. For example, any straight flush is also a straight and a flush, but would simply be described as a straight flush since that category outranks the categories straight and flush. And it is not possible to have a five high or six high hand because it would also be a straight and the category straight outranks high card.

Note that when considering whether a hand is a straight or straight flush, an Ace can be treated as either as a 1 (called low, for example the hand AH, 2D, 3C, 4H, 5S is a straight) or as a 14 (called high, for example the hand 10H, JD, QC, KH, AS is a straight). An Ace cannot be treated as both low and high in the same hand. Note that the order in which the cards are listed in the hand does not matter, so that the hand 5S, 2D, 4H, AH, 3C (these are the same cards as in the first example of a straight but in a different order) is also a straight.

Your program should represent a card by storing the cards kind and suit as follows. A cards kind should be the integer 1 if it is an Ace, the integer 2 if it is a two, the integer 3 if it is a three, etc., the integer 10 if is a ten, the integer 11 if it is a Jack, the integer 12 if it is Queen, and the integer 13 if it is a King. The cards suit should be the integer 0 if it is a Diamond, 1 if it is a Heart, 2 if it is a Club, and 3 if it is a Spade. So a card consists of two pieces of data, but we would like to be able to treat a card a single thing (for example, we would like to be able to return a card from a method). Thus, your program should use an array (one-dimensional) of integers with two elements to represent a card. The first element represents the cards kind and the second element represents the cards suit.

Write a method with the following header which generates a random card by randomly generating integers in the appropriate ranges for the cards kind and suit. (Note that zero is valid for the suit but not for the kind.) The method should return a reference to an array of integers containing two elements the first element represents the cards kind and the second the cards suit.

public static int[] drawCard()

To represent a 5-card hand, use a two-dimensional array with 5 rows and 2 columns. The 5 rows represent the 5 cards. You can think of each row as a one-dimensional array representing one card. That is, the first column represents each cards kind. The second column represents each cards suit.

Write a method with the following header which generates a random 5-card hand. It should make one or more calls to drawCard()to generate each card in the hand. Before adding a card to the hand, it must check whether a card with the same kind and suit already appears in the hand. If so, it must not add the card to the hand but instead continue calling drawCard()until a card is generated whose combination of kind and suit does not yet appear in the hand. Once a hand consisting of 5 distinct cards has been generated, the method should return a reference to the two dimensional array representing the hand.

public static int[][] drawHand()

To repeat, you must ensure that no card appears twice in the same hand. For example, the hand 2D, AC, 9S, 2D, 9H is not a legal hand because the two of diamonds appears twice. Of course it is fine that there are two 9s in this hand because they are of different suits.

Next, write a method with the following header that classifies the hand into one of the following categories, which are listed in increasing order of rank. The method should return an integer from 1 to 17 indicating the highest of the 17 ranks below which the hand satisfies. You must remember that when considering whether a hand is a straight or straight flush, an Ace can count as either a 1 or a 14, but not both. A Royal Flush is a Straight Flush in which a 10 is the lowest ranking card in the hand, such as 10S, JS, QS, KS, AS. Again, order does not matter, so QH, 10H, AH, KH, JH is also a Royal Flush.

public static int classifyHand(int[][] hand)

1. Seven high
2. Eight high
3. Nine high
4. Ten high
5. Jack high
6. Queen high
7. King high
8. Ace high
9. One Pair
10. Two pair
11. 3 of a kind
12. Straight
13. Flush
14. Full house
15. 4 of a kind
16. Straight flush
17. Royal Flush

Your main method should generate 10,000,000 random hands by making calls to drawhand and classify each hand by calling classifyHand. It should keep counts of the number of hands that fall into each category above. For each of the first 50 hands (out of the 10,000,000 hands) generated, your program should display the hand number (1-50), the five cards in the hand including the kind and suit of each card using the same notation used here, and the name of the (highest) appropriate rank of the hand from the 17 categories above. After the first 50 hands, display the hand count, hand, and hand rank only if the count of the hands so far for that category is ten or less.

After 10,000,000 random hands have been generated, display the name of each hand category followed by the percentage of hands (rounded to 5 decimal places) that fell into that category. After printing the percentages for categories 1-8 (which are sub-categories of the High Card category), print a blank line followed by a High Card category with the total percentage from the sub-categories 1-8. Then continue printing the percentages for categories 9-17.

Sample Ouput

Hand 1. AD 10S 3C 5H 6D : Ace high
Hand 2. 6H JS 7S 5D 9D : Jack high
Hand 3. 5S 4H AS 2D 2H : One Pair
Hand 4. 9S 7H 7S 6S 8C : One Pair
Hand 5. 6H AC 5C AS 3D : One Pair
Hand 6. 6H 2D 4C JD 4S : One Pair
Hand 7. QD AD 6D 8D 6S : One Pair
Hand 8. 3S 6D 6S JH 3C : Two pair
Hand 9. 4H 6C AH 5H 9H : Ace high
Hand 10. QD JC 10H 10D 4S : One Pair
Hand 11. 7S 4H 8D 10H AC : Ace high
Hand 12. 9C 6H 4D 10D JS : Jack high
Hand 13. 3C KC 10C 10D 9H : One Pair
Hand 14. 2S 3D 2D 6D JS : One Pair
Hand 15. 5C 10S 3S 4S 6C : Ten high
Hand 16. 2D KC 9D QD 7H : King high
Hand 17. 5C 5S 7D 2C 6D : One Pair
Hand 18. 8D JD 5S AS KC : Ace high
Hand 19. 6D QH AD KH JD : Ace high
Hand 20. AH JH 8C 8S 7C : One Pair
Hand 21. 10H 10D 4C 6D KH : One Pair
Hand 22. 3S 10S 6H 2C AD : Ace high
Hand 23. 2S 9S 10C 10H 3C : One Pair
Hand 24. 9D QS 3D 3C 9C : Two pair
Hand 25. 4S JH QC 10C AH : Ace high
Hand 26. 6H 5H 7C 4S 2S : Seven high
Hand 27. 2C 3C 9S 4S QH : Queen high
Hand 28. QC 5D 4C 10D JS : Queen high
Hand 29. 7S 5H KD AS 4D : Ace high
Hand 30. 10S 8C 5D 6D KH : King high
Hand 31. 8S JD 4C 9C KS : King high
Hand 32. QS JH KD 7S 8D : King high
Hand 33. 7S KH 9C 9H 6C : One Pair
Hand 34. AC 2H 4C AD 6S : One Pair
Hand 35. JS 9S 10H 4C 3S : Jack high
Hand 36. 8S 4C JH 2S 8D : One Pair
Hand 37. QD 8C 7S 4H 7C : One Pair
Hand 38. KC 5H 2C AD 5S : One Pair
Hand 39. 8D 3H 7C QD 8C : One Pair
Hand 40. JD 10H 8C 7C 6H : Jack high
Hand 41. 6H 6D QC 6S 5D : 3 of a kind
Hand 42. 5C JC 2H AC JD : One Pair
Hand 43. AS 5C 3H JH 9D : Ace high
Hand 44. 9S KD 5D 7H AH : Ace high
Hand 45. 2C 10C 9S 6S 3H : Ten high
Hand 46. 8H QH 5H 7C 6C : Queen high
Hand 47. 5H 7S 4C AD 9H : Ace high
Hand 48. 7D 5C JD AD AH : One Pair
Hand 49. JC 3C 4C KD JD : One Pair
Hand 50. 6S AD QS 2S QC : One Pair
Hand 52. 7D 8D 2H 9C 5D : Nine high
Hand 54. 5H 6H QD 5D QC : Two pair
Hand 55. QD 9D 4D 9H 4C : Two pair
Hand 56. 2C JC 3S 5C 9D : Jack high
Hand 58. QS 2S 7D 6C 10D : Queen high
Hand 60. 8S 7H AC 8C AH : Two pair
Hand 61. 6S 7H 3D KH 4D : King high
Hand 62. QH 2H 10D 8D 7D : Queen high
Hand 64. 7C QS 6D 4C JH : Queen high
Hand 71. 3D 5H 7H JD KC : King high
Hand 78. 7C JD 6D 10S 2H : Jack high
Hand 79. JH 5H 10C QS KC : King high
Hand 82. KH JC 7S 3C 4H : King high
Hand 85. 2C 8C 10C 5D 4D : Ten high
Hand 92. 5C 2H 5H 2S 4S : Two pair
Hand 93. 7D 6D 3C 3H 6S : Two pair
Hand 94. 8S KD 8H KH 6S : Two pair
Hand 95. 10S 5H KS 2D 8C : King high
Hand 96. 8D 5D 7C KD 10D : King high
Hand 104. 3H 7C 4D 6C 8C : Eight high
Hand 107. 9H 5H 7S 5C 5D : 3 of a kind
Hand 109. 6S 2S JC 2C 6D : Two pair
Hand 112. 9D 3D 9S 5D 5C : Two pair
Hand 114. 8D 4H JS QD 2H : Queen high
Hand 118. 2S 10H 3C 8C QS : Queen high
Hand 120. 9H 6C 4D QC JC : Queen high
Hand 121. QD QH JH QS 10S : 3 of a kind
Hand 126. 4H 2C 3D QC 6C : Queen high
Hand 132. 4C AD 4H JH 4S : 3 of a kind
Hand 133. 6D 3C 2S 7D 4C : Seven high
Hand 143. 4S 7S 2S 3S 10D : Ten high
Hand 148. 10S 3C 4H JD 9D : Jack high
Hand 149. 5S JH 6D 8H 9D : Jack high
Hand 157. 7S 8S 8D 2H 8H : 3 of a kind
Hand 167. 4H 7D 8H 3D 6C : Eight high
Hand 169. 4S 5D 3D 6D 2H : Straight
Hand 172. 2C 10D 6H 4D 9H : Ten high
Hand 173. 2D JS 3H 4C 9H : Jack high
Hand 176. 5C 9C 2H 4C JD : Jack high
Hand 184. 2H 3D 7H 10S 8D : Ten high
Hand 201. 6H 6D KS 6S 4S : 3 of a kind
Hand 208. 5D 9C 7S 3S 2H : Nine high
Hand 209. 2C 10C 8H 4S 6H : Ten high
Hand 211. 10H 7C 2H 5S 9S : Ten high
Hand 230. 5S 5C 2S 5H 9S : 3 of a kind
Hand 257. 4C 3D 5C 2C 6C : Straight
Hand 266. 2D 6H 5H 9C 3S : Nine high
Hand 271. 4S 3H 4C 6H 4H : 3 of a kind
Hand 276. 6H 8H 2S 7H 10D : Ten high
Hand 289. 2H 4D AC 5H 3D : Straight
Hand 307. 3C 10H 9S 7C 2C : Ten high
Hand 309. 6D 3S 7C 7D 7S : 3 of a kind
Hand 323. 7D 9S 7C 2H 7S : 3 of a kind
Hand 351. 7C 3D 2S 9D 6H : Nine high
Hand 361. 9D 7S 5D 6D 8D : Straight
Hand 410. 9D 5D 6S 8S 3D : Nine high
Hand 431. 9H 5D 7C 3D 4H : Nine high
Hand 452. 2H 8S 4H 7C 5H : Eight high
Hand 487. QH 8C JH 10D 9D : Straight
Hand 501. 8D 6C 2H 4D 7C : Eight high
Hand 517. 4S 2C 9D 3H 8S : Nine high
Hand 544. 8C 4S 7S 3S 5D : Eight high
Hand 566. 4C 3H 6S 2S 8S : Eight high
Hand 617. 3C 6H 2H 7H 4H : Seven high
Hand 624. 8D 6D 2C 4S 7C : Eight high
Hand 678. 5D 8S 6C 7S 3H : Eight high
Hand 708. 9S 4S 5C 8D 3S : Nine high
Hand 709. 2S 3D 9H 4S 7H : Nine high
Hand 729. 6D 7C 5D 2S 9C : Nine high
Hand 1011. 5S 7H 6D 9S 8D : Straight
Hand 1113. 5S 7C 3D 4H 8S : Eight high
Hand 1190. JC QC 2C AC 3C : Flush
Hand 1219. 7C 2H 6D 5H 3H : Seven high
Hand 1232. AC JC 8C 3C 4C : Flush
Hand 1237. 5C 7H 8H 2C 4H : Eight high
Hand 1247. 3H 5D 7H 2H 4H : Seven high
Hand 1451. QD KC AD JH 10D : Straight
Hand 1598. 4D 7S 2H 6D 5C : Seven high
Hand 1632. 8S 5H 4H 7S 6D : Straight
Hand 1764. 9H 8D JC QC 10C : Straight
Hand 1777. 2S 10S 3S 6S KS : Flush
Hand 1880. 3S 10S 4S KS 8S : Flush
Hand 1890. AS 10S 10C AH AD : Full house
Hand 1894. 4H 2S AC 3H 5D : Straight
Hand 1938. 2S 2D 2C 2H 5S : 4 of a kind
Hand 2161. 2S 2D 4C 2H 4H : Full house
Hand 2421. 3D 4D 10D QD JD : Flush
Hand 3189. 8S 7S 2S KS QS : Flush
Hand 3915. 3H 2S 5H 4D 7C : Seven high
Hand 4117. 3D 3C 3S 3H 7D : 4 of a kind
Hand 4461. 8S 8D 6C 8C 8H : 4 of a kind
Hand 4609. 2H QS QD QH 2C : Full house
Hand 4846. 5S 2C 3D 7C 6S : Seven high
Hand 4895. 3C 7D 5H 2C 6D : Seven high
Hand 5160. 9S 10H 10D 9H 9C : Full house
Hand 5446. 6D 6S KD 6C 6H : 4 of a kind
Hand 5730. 5S 9S 4S 2S JS : Flush
Hand 6067. 10D JD 8D 5D 2D : Flush
Hand 6273. AH 3H 3S 3D 3C : 4 of a kind
Hand 6802. 10S 5D 5C 10C 5S : Full house
Hand 7507. JS 2S QS AS 4S : Flush
Hand 7662. 4C 7C 5C 2H 3H : Seven high
Hand 7923. QD QC QH 7D 7H : Full house
Hand 8160. 4H 9H 4D 9C 9S : Full house
Hand 8507. JS 5S JC JD 5C : Full house
Hand 8932. 6S 5S 2S KS 4S : Flush
Hand 8942. KC KS 5S KH 5C : Full house
Hand 9347. 4H 4S JH 4D JD : Full house
Hand 9686. 9C 9D 9H KS 9S : 4 of a kind
Hand 10069. 10D 7S 10H 10C 10S : 4 of a kind
Hand 10674. 4S 6D 6H 6C 6S : 4 of a kind
Hand 18032. QS QH QC QD JS : 4 of a kind
Hand 22509. 4D 4H 4C 4S KC : 4 of a kind
Hand 80396. 9S 10S 7S 8S JS : Straight flush
Hand 208292. 9C 7C 10C 6C 8C : Straight flush
Hand 219903. 3C 2C 4C 5C AC : Straight flush
Hand 235328. 5H 9H 6H 7H 8H : Straight flush
Hand 288837. 6D 7D 5D 4D 3D : Straight flush
Hand 301050. QC JC 10C KC 9C : Straight flush
Hand 437896. 6D 4D 5D 8D 7D : Straight flush
Hand 459758. 9S JS QS KS 10S : Straight flush
Hand 516564. 4C 6C 7C 5C 3C : Straight flush
Hand 518984. 3C 7C 5C 4C 6C : Straight flush
Hand 1608113. JS AS 10S KS QS : Royal Flush
Hand 1655103. KD JD QD AD 10D : Royal Flush
Hand 1837105. JH AH KH QH 10H : Royal Flush
Hand 2713557. JD 10D QD AD KD : Royal Flush
Hand 3222512. AC JC 10C QC KC : Royal Flush
Hand 4132227. AH 10H KH QH JH : Royal Flush
Hand 4674045. QH KH AH 10H JH : Royal Flush
Hand 4969012. JD AD KD QD 10D : Royal Flush
Hand 5109153. QC JC 10C AC KC : Royal Flush
Hand 5183617. JH 10H KH QH AH : Royal Flush

Seven high: 0.15681%
Eight high: 0.55146%
Nine high: 1.33700%
Ten high: 2.70238%
Jack high: 4.90351%
Queen high: 8.20557%
King high: 12.92092%
Ace high: 19.32587%

High Card: 50.10352%
One Pair: 42.26590%
Two pair: 4.74646%
3 of a kind: 2.12475%
Straight: 0.39256%
Flush: 0.19748%
Full house: 0.14407%
4 of a kind: 0.02377%
Straight flush: 0.00131%
Royal Flush: 0.00018%

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.