Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A game of blackjack may involve any number of players (but for our purposes, thr

ID: 3761015 • Letter: A

Question

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:

1 The dealer shuffles the deck and deals two cards "face up" (with the front of the card showing) to each player.

2 The dealer deals one card "face down" (with only the back showing) and one card "face up" to himself.

3 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.

4 The hit-or-stand process is then repeated for each other player.

5 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.

6 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.

BOTH card.java and Deck.java Are been provide by the instructor

============Card.java================

// 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===========

// 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

       Random rand = new Random();

       ArrayList<String> totalcards = new ArrayList <String>();

       for(int i=0; i<=52;i++){

          

       }

      

   }

  

   // 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

   }

}

Explanation / Answer

Card.Java

import java.util.*;

public class Card implements Comparable
{
   private int suit;
   private int face;
  
   private static final int ACE      = 1;
        private static final int TWO      = 2;
  
        private static final int THREE    = 3;
  
        private static final int FOUR     = 4;
  
        private static final int FIVE     = 5;
  
        private static final int SIX      = 6;
  
        private static final int SEVEN    = 7;
  
        private static final int EIGHT    = 8;
  
        private static final int NINE     = 9;
  
        private static final int TEN      = 10;
  
        private static final int JACK     = 11;
  
        private static final int QUEEN    = 12;
  
         private static final int KING     = 13;
   private static final int SPADES   = 0;
  
        private static final int HEARTS   = 1;
  
        private static final int CLUBS    = 2;
  
    private static final int DIAMONDS = 3;
  
  
  
   public GetValue()
   {
       int TEN =10 ;
   }

   public String toString()
   {

       String[] r = {"", "SPADES", "CLUBES", "DIAMONDS", "HEARTS"};
       String[] c = {"", "","ACE", "TWO", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
       return str[c] + " of " + color[r];
}
}

Blackjack.java


import java.util.Scanner;

public class Blackjack
{
   static Deck deck = new Deck();
   static Hand player = new Hand();
   static Hand dealer = new Hand();

   public static void main(String[] args)
   {
       Blackjack game = new Blackjack();
       deal();
       if (finishPlayersHand()) return;
       if (finishDealersHand()) return;
       wrapUpScoring();
   }

   static void deal()
   {
       player.hit(deck.draw());
       dealer.hit(deck.draw());
       player.hit(deck.draw());
       dealer.hit(deck.draw());
       System.out.println("Dealer's up card = " + dealer.lastCard() + ' ');
       System.out.println("Player's hand is: ");
       System.out.println(player);
   }

   static void finishPlayerHand()
   {   //returns true if player busts; otherwise
       // player is still in game
       System.out.println("Do you want a hit (y/n): ");
       String reply = input.next();
       while (reply.equalsIsIgnoreCase("y"));
       {
           player.hit(deck.draw());
           System.out.println(player.lastCard());
           if (player.getScore() > 21)
           {
               System.out.println("You busted!");
           }
       }


// I guess there is a } missing here to finish finishPlayerHand


       static void finishDealerHand()
       {
           System.out.prinln(" " + "Dealer's hand is: " + dealer);
           while(dealer.getScore() < 17)
           {
               System.out.print("Dealer draws: ");
               dealer.hit(deck.draw());
               System.out.println(dealer.lastCard());
               if (dealer.getScore() > 21)
               {
                   System.out.println("Dealer busted!");
                   ++playerwins;
               }
           }

       }

       static void wrapUpScoring()
       {
           if (player.getScore() > dealer.getScore())
           {   System.out.println("You Win!");
           }
           else if (player.getScore() < dealer.getScore())
           {   System.out.println("Dealer Wins!");
           }
           else if (player.getScore() == dealer.getScore())
           {   System.out.println("The Player and the Dealer have tied.");
           }      
       }
   }

Hand.Java

Deck.Java

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote