How do you check if a hand of five cards is a full house I w
How do you check if a hand of five cards is a full house? I want it to return true if the hand is a full house, which will be run by a separate class.
Some stuff that popped up frequently: card is called by getCard(index), hand.size() returns the size of the hand (5), .getSuit() and .getRank() return a card\'s suit and rank respectively, compareTo compares the suits of two cards
public static boolean isFullHouse(){
Solution
Here is the code for you:
public static boolean isFullHouse()
{
int type1Count = 0, type2Count = 0;
char type1Card = \' \', type2Card = \' \';
for(int i = 0; i < 5; i++)
{
char rank = getCard(i).getRank();
if(type1Count == 0)
{
type1Card = rank;
type1Count = 1;
}
else if(type1Card == rank)
type1Count++;
else if(type2Count == 0)
{
type2Card = rank;
type2Count = 1;
}
else if(type2Card == rank)
type2Count++;
else
return false;
}
if(type1Count == 2 && type2Count == 3)
return true;
else if(type1Count == 3 && type2Count == 2)
return true;
return false;
}
