64.5k views
4 votes
In Poker, a "full house" occurs when your five cards contain three of one card and two of another. For example: "K", "K", "5", "K", "5" would be a full house as there are 3 Kings and two 5's.

Create a method that determines if a "hand" of 5 cards (which you can take in in your main method, stored in an array) is a full house. This method should be called fullHouseCheck in JAVA. It will take an array as input and will return nothing. If it is a full house, you should print which card is the 3 of a kind, and which card is the two of a kind. Otherwise you should print "Not a full house".

1 Answer

4 votes

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');

}

}

User Wilson Toribio
by
7.9k points