Class PokerHand

java.lang.Object
  extended by PokerHand

public class PokerHand
extends Object

Class representing a Poker Hand of five cards. The hand is an array of Cards.


Constructor Summary
PokerHand(Card c1, Card c2, Card c3, Card c4, Card c5)
          Constructor creating a hand of five cards.
PokerHand(int handType)
          Debug constructor to make testing the class easier.
 
Method Summary
 Card getCard(int i)
          Accessor returning a card from the PokerHand
 int getNumDiffCards()
          Determines the number of different cards in the PokerHand Precondition: Hand is sorted.
 boolean isFlush()
          Determines if all five cards are of the same suit.
 boolean isFullHouse()
          Determines if the hand is a full house.
 boolean isOnePair()
          Determines if the hand has exactly one pair.
 boolean isStraight()
          Determines if the hand is a straight.
 boolean isThreeOfKind()
          Determines if a hand contains three of a kind only.*************************
 boolean isTwoPair()
          Determines if a hand contains two pair only.
 void showHand()
          Outputs the PokerHand to the monitor.
 void sortHand()
          Sorts the PokerHand according to the cardNum.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PokerHand

public PokerHand(Card c1,
                 Card c2,
                 Card c3,
                 Card c4,
                 Card c5)
Constructor creating a hand of five cards.

Parameters:
c1 - Card 1
c2 - Card 2
c3 - Card 3
c4 - Card 4
c5 - Card 5

PokerHand

public PokerHand(int handType)
Debug constructor to make testing the class easier. Various hands are created to the methods in this class. Type 1 Three of a Kind Type 2 Two pair Type 3 One pair Type 4 Straight Type 5 Flush Type 6 Full House

Parameters:
handType - Allows for selecting different PokerHands for testing.
Method Detail

getCard

public Card getCard(int i)
Accessor returning a card from the PokerHand

Parameters:
i - the card number to return. 0<=i<=4
Returns:
Card located at index i.

 

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 

 

 


getNumDiffCards

public int getNumDiffCards()
Determines the number of different cards in the PokerHand Precondition: Hand is sorted.

Returns:
the number if different cardNum values. Two pair would return a 3. four of a kind would return a 2, a straight would return a 5, full house would return 2. returns false otherwise.

 

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 

 

 


isFlush

public boolean isFlush()
Determines if all five cards are of the same suit. Precondition: none

Returns:
true if all five Cards have the same suitNum values. returns false otherwise.

 

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 

 


isFullHouse

public boolean isFullHouse()
Determines if the hand is a full house. Precondition : Hand is sorted

Returns:
true if there are two different cards and second and fourth cards do not contain the same cardNum value.

 

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 

 


isOnePair

public boolean isOnePair()
Determines if the hand has exactly one pair. Precondition: hand is sorted.

Returns:
true if there are exactly four different cards. returns false otherwise.

 

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 

 


isStraight

public boolean isStraight()
Determines if the hand is a straight. At this point assume Ace is always high. Precondition: Hand is sorted.

Returns:
true if the hand has five different cards and the difference between the first cardNum and the last cardNum is 4. returns false otherwise.

 

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 

 


isThreeOfKind

public boolean isThreeOfKind()
Determines if a hand contains three of a kind only. A full house or four of a kind would return false. Precondition: hand is sorted.

Returns:
true if there are three different cards (Full house would return 2 different cards as would four of a kind.) and the first and third card have the same cardNum values or the second and fourth card have the same cardNum values or the third and fifth cardNum values are the same. returns false otherwise.

 

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 

 


isTwoPair

public boolean isTwoPair()
Determines if a hand contains two pair only. Precondition: hand is sorted

Returns:
true if there are three different cards and the first and third have different cardNum values and second and fourth have different cardNum values and third and fifth have different cardNum values. returns false otherwise.

 

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 

 


showHand

public void showHand()
Outputs the PokerHand to the monitor.

 

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L

 


sortHand

public void sortHand()
Sorts the PokerHand according to the cardNum. cardNum values : Ace - 14, King - 13, Queen - 12, Jack - 11, Ten - 10, Nine - 9, ... It sorts the hand from smallest cardNum value to largest cardNum value. This method must be working to implement the methods to determine the type of card hand. This method should be call at the conclusion of all constructors.

Student Name : H K N O P Sh Sm W L


Student Email :  H K N O P Sh Sm W L