≡ Menu

Java Practice Assignment #6 – Texas Holdem Poker

Before we launch into this assignment, let’s take a look at the solution for assignment 5:

Assignment #6 – Fun with Enums

In this assignment we are going to use our knowledge of Enums to create a Texas holdem poker game!

If you aren’t familiar with Texas holdem poker, you can become acquainted with the generic rules of poker here.

This particular assignment won’t be to implement the entire breadth of the game, but rather, to implement the key elements of the game of poker so that we can expand on it later. So let’s talk about the elements that you’ll need to implement for this assignment.

You are required to create a Deck of Cards that can be used in our poker game. The deck should be a standard deck of cards consisting of 52 cards made up of 4 different Suits (diamonds, clubs, hearts, spades) with Values ranging from TWO to ACE.

Once you have your Deck of cards setup, the next thing you need to do is be able to:

  • Shuffle your deck
  • Deal cards to Players

Having said that, you will also need to create Players, these players will have one Hand of cards. Each hand will consist of two distinct cards from the deck.

Not only do you need to deal cards to players, but you also need to deal the “community cards”. For this iteration of the assignment, let’s just deal five community cards right away. I don’t want to put the “betting” aspect into this assignment just yet.

Once you have dealt all players their hands (two cards each), and you have dealt the five community cards, then you’ll need to figure out which player has the best hand. To do this, you’ll need to know which type of hand beats another, so here’s the list:

(picture credit goes to www.betshoot.com)

You’ll need to output each players’ hand in the console window, as well as the community cards. Once you determine which player is the winner, you should output which player won and with what hand. In the event that there is a tie (i.e. two players hold the same winning hand), you’ll need to determine which of the winning hands has the higher value cards. So if both players have three of a kind, then the player with the three higher value cards wins (i.e. Player 1 has three jacks, but Player 2 has three aces… aces > jacks therefore Player 2 wins).

A draw will occur only if the values of the winning hands are exactly the same (i.e. two players have three of a kind with kings and identical ‘non-winning’ cards)… In the event that two players each have the same winning cards, but different non-winning cards (i.e. Player1 has three aces a king and a jack, Player2 has three aces, a jack and a four), then the player with the higher “kicker” card wins (i.e. Player1 wins because their king kicker beats Player2’s jack kicker).

Note: This assignment is more difficult than most other assignments I have posted on this blog. It took me roughly 12 hours of coding to complete this assignment. The good news for you is that I have included a good chunk of the coding in the assignment source files that you can download below.

What You’ll Learn

This assignment should make heavy use of Data Structures, namely Lists and Maps. Everybody’s solution will be different, so if you don’t use these data structures, then no worries… However, I do believe you will need to use them to make your life a little easier.

You will also learn how to Sort Collections, this will be mandatory, as it will be very difficult to determine which player has won without being able to sort the cards.

My solution even uses a little Recursion, now whether or not you choose to do this is up to you, but I believe it made my solution simpler.

Click Here to View the Assignment Files on GitHub

Also, here’s the GitHub Clone URI: https://github.com/tp02ga/JavaPracticeAssignment6.git

{ 5 comments… add one }
  • Robb G April 11, 2013, 9:14 pm

    Trevor, thanks for this assignment! This was the first of your assignments that I tried. You put a lot of work into this and it was a great mix of learning by reading through someone else’s code and having to figure some of it out myself. I used lists but not maps, and I’m wondering if my checkforhand methods would be more concise if I did. I look forward to comparing your solution with what I came up with. It took me a while to figure out how to get the Junit tests to work in netbeans, but once I did it was fun to be able to run your tests.class after each method I wrote and see the progress increase to 100% of tests passing. I listened to almost all 22 of your episodes in a week’s time and enjoyed them. I had read through a book on java a couple of years ago and wrote a couple programs and I remember back then thinking it would be cool to be able to learn about Java on my way to work while listening to a podcast, and I tried the Java Posse but they weren’t really what I was looking for in terms of educational substance.

  • Alvin October 9, 2014, 8:12 pm

    This is really great!

  • Sam April 6, 2015, 6:38 pm

    Hey thanks a lot for this assignment! It’s a simmilar one to a project I have to do for school, but I’m still having some problems. How can you set the players who folded, out of the current game? I’m really having some difficulties with that part 🙂

  • Adrian October 26, 2017, 1:48 am

    Hi Trevor, really enjoying the journey to learning Java so far. I feel like I’ve been able to grasp most of the content so far quite well, however when I receive these assignments they just look so confusing to me because there is so much code already written into the IDE.

    Would you be able to give me some guidance on the first steps that I should take for completing the Poker assignment (6), it is a little overwhelming.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.