Write a C++ program to simulate a card distribution scheme among Dealer, Player
ID: 656082 • Letter: W
Question
Write a C++ program to simulate a card distribution scheme among Dealer, Player and Card Shuffler in the black jack game by the Object Oriented Programming (OOP). The program should do the minimum stated below.
Card Shuffler
A card shuffler shuffles the N decks of cards, where N is defined by the user.
A card shuffler distributes a different card to the dealer everytime.
Dealer
A dealer has a name.
A dealer retrieves a card from the shuffler.
A dealer distributes the card to the player.
Player
A player has a name.
A player retrieves a card from the dealer.
A player displays all the cards at his/her hands.
Explanation / Answer
// The BlackJack class provides an implementation of a single // deck blackjack game. It makes use of the Hand class to // represent a player's hand and the Deck class to represent // the deck of cards for the game. // //************************************************************* import jss2.exceptions.*; import java.util.*; public class Blackjack { Hand dealer; //to hold the dealer's cards Hand player; //to hold the player's cards Deck newdeck; //a set of cards public Blackjack(Hand dlr, Hand plr) { dealer = dlr; player = plr; newdeck = new Deck(); }//Blackjack constructor /*********************************************************** deal method - deals the intitial cards to each player ***********************************************************/ public void dealInitialCards() { dealer.newCard(newdeck); dealer.newCard(newdeck); player.newCard(newdeck); player.newCard(newdeck); }//end deal method /*********************************************************** hit method - adds the next random card from the deck to the given player's hand ***********************************************************/ public Card hit(Hand whohit) { Card result = whohit.newCard(newdeck); return result; }//end hit method /*********************************************************** handValue method - returns the value of the given player's hand ***********************************************************/ public int handValue(Hand whohand) { int result = whohand.getHandValue(); return result; }// end handValue method /*********************************************************** discard method - discards a given card from the given player's hand or throws an exception if the card is not in the hand ************************************************************/ public void discard(Hand whodis, Card discrd) throws ElementNotFoundException { Card card=null; boolean found = false; Iterator scan = whodis.iterator(); while (scan.hasNext() && !found) { card = scan.next(); if(discrd.equals(card)) { whodis.remove(card); found = true; } } if(!found) throw new ElementNotFoundException("BlackJack"); }//end discard /*********************************************************** blackj method - tests to see if the player's hand has a value of 21 ***********************************************************/ public boolean blackj() { boolean result = false; if(player.getHandValue() == 21) result = true; return result; }//end blackj /*********************************************************** bust method - tests a given player's hand to see if they have gone over 21 ***********************************************************/ public boolean bust(Hand whobust) { boolean result = false; if(whobust.getHandValue() > 21) result = true; return result; }//end bust /*********************************************************** dealerPlays method - adds cards to the dealer's hand until the value is >= 16 ***********************************************************/ public Hand dealerPlays() { Hand result = dealer; while(dealer.getHandValue()Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.