Question: Java Question Question: (Card Shuffling and Dealing) Modify the code so that the card-dealing function deals a five-card poker hand. Include the following methods: a)
Java Question
Question: (Card Shuffling and Dealing) Modify the code so that the card-dealing function deals a five-card poker hand. Include the following methods: a) Determine whether the hand contains a pair. b) Determine whether the hand contains two pairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determine whether the hand contains four of a kind (e.g., four aces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of consecutive face values).
Please help me, I completely don't understand the rules of Poker and not sure where to start when modifying the given code in java:
// Card.java file
public class Card { private final String face; // face of card private final String suit; // suit of card
public Card( String cardFace, String cardSuit ) { this.face = cardFace; this.suit = cardSuit; } public String getFace() { return this.face; } public String getSuit() { return this.suit; }
public String toString() { return face + " of " + suit; } }
-----------------------------------------
//DeckOfCards.java file
import java.security.SecureRandom; import java.util.Arrays;
public class DeckOfCards { private static final SecureRandom randomNumbers = new SecureRandom(); private static final int NUMBER_OF_CARDS = 52;
private Card[] deck = new Card[NUMBER_OF_CARDS]; // array of cards private int currentCard = 0; String[] faces = { "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" }; String[] suits = { "Hearts", "Diamonds", "Clubs", "Spades" }; public DeckOfCards() { deck = new Card[NUMBER_OF_CARDS]; currentCard=0;
for ( int count = 0; count < deck.length; count++ ) { deck[ count ] = new Card( faces[ count % 13 ], suits[ count / 13]); } }
public void shuffle() { currentCard = 0;
for ( int first = 0; first < deck.length; first++) { int second = randomNumbers.nextInt( NUMBER_OF_CARDS ); Card temp = deck[ first ]; deck[ first ] = deck [ second ]; deck[ second ] = temp; } }
public Card dealCard() { if ( currentCard < deck.length ) { return deck[ currentCard++ ]; } else { return null; } } /* public HandContainPair() { } */ /* public HandContainTwoPair() { } */ /* public HandContainThreeOfAKind() { } */ /* public HandContainFourOfAKind() { } */ /* public HandContainFlush() { } */ /* public HandContainStraight() { } */ /* public HandContainFullHouse() { } */
-----------------------------------------
// DeckOfCardsTest.java file
public class DeckOfCardsTest {
public static void main( String[] args ) { DeckOfCards myDeckOfCards = new DeckOfCards(); myDeckOfCards.shuffle();
for ( int i = 1; i <+ 52; i++ ) { System.out.printf( "%-19s", myDeckOfCards.dealCard() );
if ( i % 4 == 0 ) { System.out.println(); } } } }
-----------------------------------------
Any help is greatly appreciated and thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
