back to labs page

Lab 3

Poker Statistics

Concepts Covered: Algorithmic thinking, Writing a small part of a larger class, Poker

Due: Perferably at the end of the day on Wednesday

Files you need: Card.java, Deck.java, PokerHand.java, PokerHandTester.java

Turn In:

PokerHand.java, PokerStatistics.java

Background: Poker is a card game in which players bet on the value of their five-card hand (which is unknown to the other players). There are several different variations. One thing that they all have in common is the ranking and interpretations of the five-card hands. Here is a list from highest rank to lowest rank:

The above rankings are based on the probabilities of pulling five cards out of a shuffled deck of cards and it matching one of the above hands. The probabilities turn out to be:

In this project, you will write code that will faithfully model a deck of cards and a poker hand, and then you will write a program that will test your deck to make sure that it is dealing out poker hands with probabilites that are similar to those listed above.

Requirements:

Part 1: In the first part of this lab assignment, you will complete the PokerHand.java class by filling in the methods that determine determine the rank of the hand. For example, you will complete the containsPair() method which returns true if the PokerHand has two cards of the same rank. Your task is made easier thanks to the sortedHand card array which has the cards sorted in order of their rank. You can use this to your advantage. I also highly recommend coding in order, since you can use the results of earlier methods to determine the results of later methods. For instance, a Straight exists only if the hand does not contain a pair. This will be very helpful!

I have included a PokerHandTester program that you can compile and run as you're filling out your methods. It will output the rank associated with each hand, and there are example of each type of hand included. Each time you solve a contains method, write it and check to see that the PokerHandTester program is outputting the correct rank.

Part 2: In the second part of this lab assignment, you will write a program called PokerStatistics.java that deals 100000 hands of Poker using the Card class, the Deck class and the PokerHand class. This class should keep track of exactly how many times each rank appears, and it should output the percentage for each rank. Do you think that these will match the probabilities above?

In order to deal a poker hand, your program should create a deck:


Deck cardDeck = new Deck();

It should deal a poker hand from the deck:


h = new PokerHand(cardDeck.deal(),cardDeck.deal(),cardDeck.deal(),cardDeck.deal(),cardDeck.deal());

Finally, it should shuffle the deck before it deals out the next hand:


cardDeck.shuffle()