HW J5: 3-card poker
Assigned 10 November 2004
Due 5:00 p.m. on 19 November 2004



The purpose of this assignment is to gain familiarity with the Java control constructs by completing the design and implementation of classes that enable us to determine the rarity of a three-card stud poker hand, where 3-card stud poker is analogous to standard 5-card stud poker, but using 3 cards instead of 5.

You will need to submit two files for this assignment: Hand.java and HandEvaluation.java.  We are not providing skeleton code for HandEvaluation.java.  You will also need to use the Card.class file.

Background -- cards and poker

A standard deck of cards has 52 cards, the cards are split evenly into four suits: spades (♠), hearts (), diamonds () and clubs (♣).  Note that two of the suits are colored red (hearts and diamonds) and two are colored black (spades and clubs).

For each suit, there are 13 cards. Each card in a suit has a different face than the other cards in the suit. The thirteen faces are Ace, the numbers 2 through 10, Jack, Queen, and King.  The value of a numbered card is its number, a Jack has value 11, a Queen has value 12, and a King has value 13.  For our purposes, which is different than standard poker, an Ace has value 1.  A card is referenced by its face (1 or A for Ace, J for Jack, Q for Queen, K for King, or a number 2 through 10) followed by its suit (either pictorially ♣, , , and ♠, or lexicographically C, D, H, and S).  Thus, A♠ or AS or 1♠ or 1S is the Ace of spades, 5 or 5H is the 5 of hearts, and K♣ or KC is the King of clubs.

In 3-card stud poker, each player is given three cards. The three cards, after sorting them by value (so the lowest is listed first), is called a hand. A 3-card hand is classified into one six types with each type having a different worth. The player with the highest-valued hand wins.

The six possible hand types in increasing order of worth are:

A note for those who know 5-card stud poker: the rarity of hands is quite different in 3-card stud poker than in 5-card stud poker.  For example, a three of a kind is much rarer in 3-card stud poker than it is in 5-card stud poker.

Determining the rarity of 3-card poker hands

There are 52*51*50 = 132,600 different ways to pass three cards to a player - 52 possibilities for the first card, 51 possibilities for the second card (the first card cannot be handed out twice), and 50 possibilities for the third card (neither the first or second card can be handed twice). (If we were to ignore the order in which cards are passed to a player then there are only 22,100 different hands. However, we are not ignoring order.)

To determining the rarity of the different hand types you must use the following algorithm

Initialize six counters, one for each type of hand
For each card c1 in a deck do
    For each card c2 in a deck do
        For each card c3 in a deck do
            If cards c1, c2, and c3 represent a valid 3-card stud poker hand (i.e. none of
                   three cards in the hand is the same as another card in the hand)
                Determine the type of the hand and increment the associated counter
Display the counters


To assist you a class Card has implemented. The class has the following public elements.

To assist you a class Hand has also been defined and partially implemented. The class has the following implemented public elements.

Your task

You are do the following


In an effort to help you determine if your program is working correctly, there are 264 possible straight flushes, and 3,960 possible straights in 3-card stud poker.