Final answer:
To determine if a hand of 5 cards is a full house in Poker, you can create a method called fullHouseCheck in Java. This method should take an array of 5 cards as input and return nothing. If the hand contains three cards of the same rank and two cards of a different rank, it is a full house.
Step-by-step explanation:
To determine if a hand of 5 cards is a full house in Poker, you can create a method called fullHouseCheck in Java. This method should take an array of 5 cards as input and return nothing. The method should check if the hand contains three cards of the same rank and two cards of a different rank. If it is a full house, the method should print which card represents the three of a kind and which card represents the two of a kind. Otherwise, it should print 'Not a full house'.
Here is an example implementation of the fullHouseCheck method:
public static void fullHouseCheck(String[] hand) {
Map cardCount = new HashMap<>();
for(String card : hand) {
if(cardCount.containsKey(card)) {
cardCount.put(card, cardCount.get(card) + 1);
} else {
cardCount.put(card, 1);
}
}
if(cardCount.containsValue(3) && cardCount.containsValue(2)) {
for(String card : cardCount.keySet()) {
if(cardCount.get(card) == 3) {
System.out.println('Three of a kind: ' + card);
} else if(cardCount.get(card) == 2) {
System.out.println('Two of a kind: ' + card);
}
}
} else {
System.out.println('Not a full house');
}
}