Starting from:

$18.99

Rules of Blackjack Solution

For this assignment, you will implement a video card game. The game is a simplified version of blackjack, where some of the more complex rules have been eliminated. Blackjack is played with a "deck" (pile) of 52 cards. The front of each card shows symbols and numbers that identify the card. The back of each card is identical, so that you cannot tell which card it is by looking at the back.

Each card has one of 4 possible "suits": spades, hearts, clubs, or diamonds. Each suit has its own special symbol. Spade and club cards have black symbols and numbers on the front, while heart and diamond cards have red symbols. Each card also has one of 13 possible "faces": ace (A), 2, 3, 4, 5, 6, 7, 8, 9, 10, jack (J), queen (Q), or king (K). The face of a card determines its numerical scoring value. Numbered cards are worth their number of points. Jacks, queens, and kings are all worth 10 points each. Aces can be worth 1 point or 11 points, depending on the circumstances. A player's "hand" is the set of cards the player currently holds. The score of the hand is the sum of the point values of its cards. The goal in blackjack is to acquire a hand whose score is as high as possible without going over 21. The point value of an ace card is whatever is most advantageous to the player: 1 or 11, whichever would bring the score of the player's hand closer to 21 without exceeding it.

A game of blackjack may involve any number of players (but for our purposes, three or fewer), and always exactly one "dealer": the person who "deals" (hands out) the cards. Players compete against the dealer, not against each other. A player's goal in a round of blackjack is to have a higher score than the dealer, without going over 21 ("busting"). Each round of simplified blackjack proceeds as follows: The dealer shuffles the deck and deals two cards "face up" (with the front of the card showing) to each player. The dealer deals one card "face down" (with only the back showing) and one card "face up" to himself. The dealer asks the first player whether she wishes to "hit" (receive another card) or "stand" (not receive any more cards). If she chooses to stand, she will not receive any more cards this round, so her score is fixed.

The game moves on to the next player. If she chooses to hit, the dealer will deal her another card, face up, and her score increases. She will then be given the option to hit or stand again. If her score exceeds 21, she has "busted" and immediately loses this round - play will continue with the next player. Essentially, the player can continue to hit until she either decides to stand, or busts. The hit-or-stand process is then repeated for each other player. Once all players are done, it is the dealer's turn to play. First, he turns his face-down card over. Then he hits until his score is 17 or higher. The dealer cannot decide to hit or stand arbitrarily. If his score is less than 17, he must hit. If it is 17 or higher, he must stand. If the dealer busts, any players who did not bust earlier win this round. Otherwise, each player's score is compared to that of the dealer. A player wins if he has a higher score than the dealer, loses if he has a lower score, and "pushes" (ties) if he has the same score. At the end of each round, the group of players can decide whether they would like to play again.

 

a)    Complete the class definitions for Card.java and Deck.java. Write a main() method in a file called Blackjack.java that shows you have tested your Card.java and Deck.java code thoroughly. The description for the instance methods and fields are in the files attached to this assignment

b)    2.Write a main method for blackjack.java that is the game and tests the Deck.java and Card.java. Also create a Player Class and Hand Class.

 

Card.java should be answered in this following format with no changes to the signatures of the methods but additional methods can be added to the .java files.

// This class represents one playing card.

public class Card

{

        // Card suits (provided for your convenience - use is optional)

        public static final int SPADES   = 0;

        public static final int HEARTS   = 1;

        public static final int CLUBS    = 2;

        public static final int DIAMONDS = 3;

 

        // Card faces (provided for your convenience - use is optional)

        public static final int ACE      = 1;

        public static final int TWO      = 2;

        public static final int THREE    = 3;

        public static final int FOUR     = 4;

        public static final int FIVE     = 5;

        public static final int SIX      = 6;

        public static final int SEVEN    = 7;

        public static final int EIGHT    = 8;

        public static final int NINE     = 9;

        public static final int TEN      = 10;

        public static final int JACK     = 11;

        public static final int QUEEN    = 12;

        public static final int KING     = 13;

 

 

        // define fields here

        int suit;

        int face;

       

        // This constructor builds a card with the given suit and face, turned face down.

        public Card(int cardSuit, int cardFace)

        {

                //fill in this method

        }

 

        // This method retrieves the suit (spades, hearts, etc.) of this card.

        public int getSuit()

        {

                //fill in this method

        }

       

        // This method retrieves the face (ace through king) of this card.

        public int getFace()

        {

                //fill in this method

        }

       

        // This method retrieves the numerical value of this card

        // (usually same as card face, except 1 for ace and 10 for jack/queen/king)

        public int getValue()

        {

                //fill in this method

        }

 

       

}

Deck.java should be formatted similarily.

// This class represents the deck of cards from which cards are dealt to players.

public class Deck

{

        // define fields here

       

       

        // This constructor builds a deck of 52 cards.

        public Deck()

        {

                //fill this method in

        }

 

       

        // This method takes the top card off the deck and returns it.

        public Card deal()

        {

                //fill this method in

        }

       

       

        // this method returns true if there are no more cards to deal, false otherwise

        public boolean isEmpty()

        {

                //fill this method in

        }

       

        //this method puts the deck int some random order

        public void shuffle(){

               

                //fill this method in

        }

}

 

More products