Results 1 to 4 of 4
  1. #1
    dbentley18 is offline Member
    Join Date
    Nov 2016
    Rep Power

    Default A 52 card poker game

    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 player’s hand is then scored into one of a number of categories. Please read the description of Poker hand categories at:

    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.

    You program should represent a card by storing the card’s kind and suit as follows. A card’s 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 card’s 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 card’s kind and the second element represents the card’s suit.

    Write a method with the following header which generates a random card by randomly generating integers in the appropriate ranges for the card’s 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 card’s kind and the second the card’s 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 card’s kind. The second column represents each card’s 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 9’s 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 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. Please see the example output that appears at the end of this document, including the category percentages at the very end.

    Do not call any methods that come with Java which operate on entire arrays.

    If your program is written correctly, the percentages for each hand category should be very close to those predicted in the “Probability” column at:

    Sample Ouput

    Hand 1. 9S 9C QD AS 6C : One Pair

    Hand 2. JS 8S 4D JD 7S : One Pair

    Hand 3. 7S AD 10D KC 6D : Ace high

    Hand 4. JH 4S QD 3S 8C : Queen high

    Hand 5. JD 9C 7H 2C QC : Queen high

    Hand 6. 3D 3C 10C 9H QD : One Pair

    Hand 7. 4S KS JS AD 7C : Ace high

    Hand 8. 3C 5H 8D QC 5D : One Pair

    Hand 9. JD 5H 7H 2D 3H : Jack high

    Hand 10. 6C 6H 4C 7S JD : One Pair

    Hand 11. QH JH 8D AD 9D : Ace high

    Hand 12. 4C 6D 5S 3S 9D : Nine high

    Hand 13. 5C 7D 8C 5S AC : One Pair

    Hand 14. 8C 4D 5C 2H 3S : Eight high

    Hand 15. 2S JH KC AS 10C : Ace high

    Hand 16. 3C KS 8D 5S 4C : King high

    Hand 17. 6S 2D KD 4D 4H : One Pair

    Hand 18. JH 10D 10S 3H QD : One Pair

    Hand 19. 9C 10H 6H KS 8D : King high

    Hand 20. 3S 9S 3C QH QC : Two pair

    Hand 21. 7H 9S AS 10C JD : Ace high

    Hand 22. 2S AS QC AC 9C : One Pair

    Hand 23. KH 10C 4S 8H 3S : King high

    Hand 24. AH 10H 6C 8S 6D : One Pair

    Hand 25. 6C KH JD AD AH : One Pair

    Hand 26. 10C 9S 7C KD 8H : King high

    Hand 27. QC 8C 4S 4C 7C : One Pair

    Hand 28. 10C 3C QD 4S JC : Queen high

    Hand 29. 8S 6S 6D 8C AD : Two pair

    Hand 30. QC KC 4D KH 8C : One Pair

    Hand 31. 10S AH 2H 3H 8C : Ace high

    Hand 32. KC 5D 10S 4H 3C : King high

    Hand 33. 2C 9C 2H 9H 8D : Two pair

    Hand 34. 5H 6D QS 2S AD : Ace high

    Hand 35. 2H 3D 6H AH 3C : One Pair

    Hand 36. 2S 4S 8S KD 6H : King high

    Hand 37. 3C 6H 9C 7C 9H : One Pair

    Hand 38. 4D 7D KH QS JC : King high

    Hand 39. 7D AS 4C QD 8C : Ace high

    Hand 40. 5H 9H 2C 3C 5S : One Pair

    Hand 41. 9S 6C 8H 3H KH : King high

    Hand 42. KD 9S 9C 7D 3S : One Pair

    Hand 43. 4S AH 10C JH JD : One Pair

    Hand 44. QC 2D 10C 3H 5D : Queen high

    Hand 45. KD JH 5H 3C KC : One Pair

    Hand 46. 10D 4D 2H QC 7S : Queen high

    Hand 47. 9H KH 5C 2S QH : King high

    Hand 48. 8D 10C 7S AS 3D : Ace high

    Hand 49. 10C 5H QD KD 4D : King high

    Hand 50. KH 7S JH AD 3S : Ace high

    Hand 60. 6C 3D 9S 8H JH : Jack high

    Hand 61. QS QD 9H 9C 8H : Two pair

    Hand 63. 3C 10D JD 6D 4C : Jack high

    Hand 66. QH 8D 10S 5D JC : Queen high

    Hand 70. 4H 5S JC 10C 9S : Jack high

    Hand 71. 10H 8C 10S 8D 5S : Two pair

    Hand 72. 8D QC 5H 9H 10C : Queen high

    Hand 75. 3C 5C QD 4C 10C : Queen high

    Hand 78. 5H 8D QH 4C 10D : Queen high

    Hand 79. 10S 3H 3S 10D 10C : Full house

    Hand 82. 7D QD 5C 3D 6C : Queen high

    Hand 83. 10H 2D 4S 9C 6D : Ten high

    Hand 86. 2C JS 8C 10D 4C : Jack high

    Hand 91. 4C 3D 10D 4H 3S : Two pair

    Hand 104. 2D 3C 9S JD 5H : Jack high

    Hand 111. 7S 8H 2D JD 5S : Jack high

    Hand 112. 7H 8S 9H 3H 4C : Nine high

    Hand 128. 10S 4D 4H 2D 2C : Two pair

    Hand 130. 6C 2S 2C 6S 8H : Two pair

    Hand 137. 4C 6S 3D 2H JS : Jack high

    Hand 142. 5C 6D 9D 3S 10S : Ten high

    Hand 146. 6H 10H QH QD QS : 3 of a kind

    Hand 154. 6C 3S JC 4H 7D : Jack high

    Hand 156. 4C 8C 8H 4D QD : Two pair

    Hand 168. 8D 8S 8C 10C QD : 3 of a kind

    Hand 179. 4C 4H 6S KH KC : Two pair

    Hand 185. 10C 6H 9H 2H 8C : Ten high

    Hand 197. 6H 5C 2H 9D JH : Jack high

    Hand 201. 3H 5C 10S 4D 6D : Ten high

    Hand 219. 7S 7C QH 7H 9D : 3 of a kind

    Hand 229. 9D 3S 4S 7H 6H : Nine high

    Hand 232. 3D 5H 7D 9H 8C : Nine high

    Hand 245. 3H 6S 7H 8D 5C : Eight high

    Hand 251. 6D 2H 3H 9C 4D : Nine high

    Hand 262. KS 6D 6S 6C 2S : 3 of a kind

    Hand 278. 9S 3S 7C 5C 10S : Ten high

    Hand 281. 6D 9C 3C 6S 6C : 3 of a kind

    Hand 291. 5D 6C 9D 10H 8S : Ten high

    Hand 314. 5H 9D 6H 8D 10S : Ten high

    Hand 323. 8D 8C 4S JD 8S : 3 of a kind

    Hand 329. 5S 3H 2S 10C 7D : Ten high

    Hand 340. 3D QC 6H 6S 6D : 3 of a kind

    Hand 343. JD 8D 5D 7D 10D : Flush

    Hand 360. 3D 10H 2S 5D 7S : Ten high

    Hand 361. 5H JH 5C 5D QC : 3 of a kind

    Hand 362. QS JS QC KS QH : 3 of a kind

    Hand 366. 2D 9D 10H 8S 4C : Ten high

    Hand 392. 2D 2C 4D JH 2H : 3 of a kind

    Hand 500. 9H 3D 2D 6D 8H : Nine high

    Hand 526. 5D 10D KD 8D 4D : Flush

    Hand 535. 3C 2D 5H 8C 4D : Eight high

    Hand 539. 2H 4S 3C 8S 7C : Eight high

    Hand 577. 9S 5S 3S KS 7S : Flush

    Hand 578. 9C 5S 6C 3S 4H : Nine high

    Hand 599. 7C 9C 8D 3H 5S : Nine high

    Hand 636. 5H 7D 2H 8D 6S : Eight high

    Hand 644. 6D 4S 3C 8D 5H : Eight high

    Hand 660. 9H 7D 8C 2C 3H : Nine high

    Hand 666. 2D 10D QD 3D 8D : Flush

    Hand 675. 5D 7S 3H 2S 4D : Seven high

    Hand 692. 2S 3S 6C 9D 7D : Nine high

    Hand 701. 7H 3S 4D 8S 5D : Eight high

    Hand 720. 3H 2D 8H 7D 6H : Eight high

    Hand 831. 6S 4S 7C 2S 8C : Eight high

    Hand 846. 4S 9S 5S 10S JS : Flush

    Hand 889. 6H 10S 7D 8C 9D : Straight

    Hand 920. 8S 2H 5S 7C 6S : Eight high

    Hand 945. 9S 8D 8H 8C 9D : Full house

    Hand 960. 7H 5H 2H 10H 3H : Flush

    Hand 1084. QD 7D QH QS QC : 4 of a kind

    Hand 1103. JD 9S 8C QS 10H : Straight

    Hand 1108. 4H 3C AH 5C 2C : Straight

    Hand 1158. 2H KH 2C KS 2S : Full house

    Hand 1561. AC AS AD 10S AH : 4 of a kind

    Hand 1572. 5C 2C 6D 4C 7H : Seven high

    Hand 1612. 5D 7D 3D 4H 6C : Straight

    Hand 1616. 7H 3D 4S 5C 6D : Straight

    Hand 2261. 2D 6D 3C 4C 7C : Seven high

    Hand 2613. 7C 3S 4D 5C 2S : Seven high

    Hand 2622. 9H QS 8S 10S JS : Straight

    Hand 2632. 9H 8C 10D 6S 7D : Straight

    Hand 2646. 8C JH 9H 10D QC : Straight

    Hand 2829. 8S 8D 4C 8H 4D : Full house

    Hand 2952. 4S 8S 5H 6C 7S : Straight

    Hand 2956. QS 9S 7S 5S 2S : Flush

    Hand 3039. 7C 4H 6C 5H 3D : Straight

    Hand 3330. 2H 2D 10S 2C 2S : 4 of a kind

    Hand 3725. 6D 5D 3D 7D 9D : Flush

    Hand 4004. 5D 5S 5H 8S 5C : 4 of a kind

    Hand 4009. 3H 7C 6S 2D 4H : Seven high

    Hand 4232. 2C JD JC JH 2D : Full house

    Hand 4646. 10D 8D 3D JD 4D : Flush

    Hand 4901. AC KC KD AD AS : Full house

    Hand 5086. 4D JD KD 5D AD : Flush

    Hand 5283. 7H 5D 2S 4H 3S : Seven high

    Hand 5473. 5C 2H 6D 4H 7D : Seven high

    Hand 5803. 4C 4H QC 4D 4S : 4 of a kind

    Hand 6168. 7H 5H 6C 3D 2H : Seven high

    Hand 6243. 2C 3D 5D 6C 7D : Seven high

    Hand 6788. 4C 2H 6H 7D 3C : Seven high

    Hand 8311. AH 4D 4H AD AC : Full house

    Hand 8814. 8D 8H QC 8S QD : Full house

    Hand 9524. 7D 6C 6H 7S 7C : Full house

    Hand 10064. KC KD 9C KS 9D : Full house

    Hand 14410. 9D 9C 2S 9H 9S : 4 of a kind

    Hand 17982. 4D 4C AC 4H 4S : 4 of a kind

    Hand 20429. 3H 3C 3D 3S 7D : 4 of a kind

    Hand 21744. 8H 8S 8D 5D 8C : 4 of a kind

    Hand 27556. 8H 8D 8S 7C 8C : 4 of a kind

    Hand 217348. 7D 8D 9D 10D JD : Straight flush

    Hand 271151. 4C 5C 8C 7C 6C : Straight flush

    Hand 334054. 8C 10C JC 9C QC : Straight flush

    Hand 352233. 5H 6H 3H 2H 4H : Straight flush

    Hand 402603. 6S 8S 10S 7S 9S : Straight flush

    Hand 439496. 8D JD 10D 7D 9D : Straight flush

    Hand 453299. 4D 5D 6D 8D 7D : Straight flush

    Hand 490386. 8S 7S 6S 10S 9S : Straight flush

    Hand 542842. 4C 6C 7C 5C 3C : Straight flush

    Hand 563679. AD 5D 3D 4D 2D : Straight flush

    Hand 1051401. JC AC 10C KC QC : Royal Flush

    Hand 1120810. JH AH QH 10H KH : Royal Flush

    Hand 1386739. QS KS AS JS 10S : Royal Flush

    Hand 2969934. QD 10D KD JD AD : Royal Flush

    Hand 3221301. JD QD KD 10D AD : Royal Flush

    Hand 3336135. AS QS JS KS 10S : Royal Flush

    Hand 5356816. JC QC AC KC 10C : Royal Flush

    Hand 7129520. KD JD QD 10D AD : Royal Flush

    Hand 9453798. QC 10C AC KC JC : Royal Flush

    Hand 9729739. AC 10C QC KC JC : Royal Flush

    Seven high: 0.15717%

    Eight high: 0.55083%

    Nine high: 1.33554%

    Ten high: 2.70617%

    Jack high: 4.90529%

    Queen high: 8.20328%

    King high: 12.90983%

    Ace high: 19.35425%

    High Card: 50.12236%

    One Pair: 42.24548%

    Two pair: 4.76013%

    3 of a kind: 2.11443%

    Straight: 0.39225%

    Flush: 0.19764%

    Full house: 0.14268%

    4 of a kind: 0.02361%

    Straight flush: 0.00132%

    Royal Flush: 1.0E-4%

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: A 52 card poker game

    Wow, lots of text in that post.

    Do you have some specific java programming questions?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: A 52 card poker game

    That's an awful lot to go over.
    And your question is?
    Can you narrow down your problem?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: A 52 card poker game

    A lot of text with two external links. LOL! Looks like a homework dump to me.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Poker Game
    By jocdrew21 in forum New To Java
    Replies: 6
    Last Post: 06-08-2014, 09:26 PM
  2. Card Game
    By HarleyRowland in forum New To Java
    Replies: 7
    Last Post: 02-05-2013, 12:44 AM
  3. Trying to make a Poker Dice game..!
    By karibo in forum New To Java
    Replies: 1
    Last Post: 12-08-2011, 04:06 PM
  4. please help me with this card game
    By noobinoo in forum New To Java
    Replies: 13
    Last Post: 03-28-2010, 02:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts