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.

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:

*Nothing*: a hand that does not meet the requirements of any other hand type.*Pair*: a hand with exactly two of the cards having matching faces (e.g., 2♣, 2♥, and 7♥,).*Flush*: a non-straight hand with the three cards being of the same suit (e.g., 2♥, 7♥, and K♥).*Straight*: a hand with cards from at least two suits with three consecutive face values (e.g., 7♠, 8♥, and 9♠).*Three of a kind*: a hand with all cards having the same face value (e.g., K♦, K♥, and K♠).*Straight flush*: a hand with three consecutive face values of the same suit (e.g., J♥, Q♥, and K♥).

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.

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 cardc1 in a deck do

For each cardc2 in a deck do

For each cardc3 in a deck do

If cardsc1,c2, andc3 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.

- Card(int i)
- If i is in the inclusive interval 1 ... 52 then a card is configured in
the following manner
- If 1 <= i <= 13 then the card is a club
- If 14 <= i <= 26 then the card is a diamond
- If 27 <= i <= 39 then the card is a heart
- If 40 <= i <= 52 then the card is a spade
- If i % 13 is 1 then the card is an Ace;
- If i % 13 is 2, then the card is a 2, and so on.

- If i is in the inclusive interval 1 ... 52 then a card is configured in
the following manner
- String getFace()
- Returns the face of the card as a String

- String getSuit()
- Returns the suit of the card as a String

- int getValue()
- Returns the value of the card

- boolean equals(Object c)
- Returns whether c is a card that has the same face and suit as the invoking card

- String toString()
- Returns a text representation of the card. You may find this method useful during debugging.

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

- public Hand(Card c1, Card c2, Card c3)
- Creates a hand using cards c1, c2, and c3.

- public Card getLow()
- Returns the low card of the three cards in the hand

- public Card getHigh()
- Returns the high card of the three cards in the hand

- public Card getMiddle()
- Returns the middle card of the three cards in the hand

- public String toString()
- Returns a text representation of the hand. You may find this method useful during debugging. Using it 132,600 times would be excessive.

- public boolean isNothing()
- Returns ! (this.isPair() || this.isThree() || this.isStraight() || this.isFlush() || this.isStraightFlush())

- public boolean isValid ()
- Returns true if the hand has all different cards. Returns false if any two of the cards (or all three) are the same card.

You are do the following

- Submit a completed program HandEvaluation.java whose method main() performs the previously described
rarity algorithm.
- public static void main(String[] args)
- Implements the rarity algorithm given above.

- public static void main(String[] args)
- Submit a completed class
Hand.java
after designing, implementing, and adding the following
methods to the class
- public boolean isPair()
- Returns true if the low and middle cards have the same face and the high card has a different face
- Returns true if the middle and high cards have the same face and the low card has a different face
- Returns false otherwise

- public boolean isThree()
- Returns true if the low and high cards have the same face
- Returns false otherwise

- public boolean isStraight()
- Returns false if is not a straight (a straight is when the high card value minus middle card value is 1, and middle card value minus low card value is 1)
- Returns false if all three cards have the same suit
- Returns true otherwise

- public boolean isFlush()
- Returns false if
*is*a straight (a straight is when the high card value minus middle card value is 1, and middle card value minus low card value is 1) - Returns false if either the low and middle cards or the middle and high cards have different suits
- Returns true otherwise

- Returns false if
- public boolean isStraightFlush()
- Returns false if is not a straight (a straight is when the high card value minus middle card value is 1, and middle card value minus low card value is 1)
- Returns false if either the low and middle cards or the middle and high cards have different suits
- Returns true otherwise

- public boolean isPair()

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.