Question
5 public class DeckOfCards 6 { 7 8 private int currentCard; // index of next Card to be dealt (0-51) 9 private static final int
5 public class DeckOfCards 6 { 7 8 private int currentCard; // index of next Card to be dealt (0-51) 9 private static final int NUMBER_OF_CARDS = 52; // constant # of Cards 10 // random number generator 11 private static final SecureRandom randomNumbers = new SecureRandom(); 12 13 // constructor fills deck of Cards 14 public DeckOfCards() 15 { 16 17 18 19 20 21 currentCard = 0; // first Card dealt will be deck[0] 22 23 24 25 26 27 } 28 29 // shuffle deck of Cards with one-pass algorithm 30 public void shuffle() 31 { 32 // next call to method dealCard should start at deck[0] again 33 currentCard = 0; 34 35 // for each Card, pick another random Card (0-51) and swap them 36 for (int first = 0; first < deck.length; first++) 37 { 38 // select a random number between 0 and 51 39 int second = randomNumbers.nextInt(NUMBER_OF_CARDS); 40 41 // swap current Card with randomly selected Card 42 43 44 45 } 46 } 47 48 // deal one Card 49 public Card dealCard() 50 { 51 // determine whether Cards remain to be dealt 52 if () 53 return deck[currentCard++]; // return current Card in array 54 else 55 return null; // return null to indicate that all Cards were dealt 56 } 57 } // end class DeckOfCards Fig. 7.10 |
Then modify class DeckOfCards of fig 7.10 to include methods that determine whether a hand contains
a pair
two pairs
three of a kind (e.g three jacks)
four of a kind (e.g four aces)
a flush (i-e all five cards of the same suite)
a straight (i-e, five cards of consecutive face values)
a full house (i-e, two cards of one face value & three cards of another face value) [Hint: Add methods getFace and getSuit to class Card of Fig. 7.9.]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started