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

Rules of Blackjack For this assignment, you will implement a video card game. Th

ID: 3760981 • Letter: R

Question

Rules of Blackjack 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.

could you help me 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.

Card.java:

Deck.java:

Explanation / Answer

public class Card
{
public static final int SPADES = 0;
public static final int HEARTS = 1;
public static final int CLUBS = 2;
public static final int DIAMONDS = 3;
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;
private int suit;
private int face;
private boolean faceup;
public Card(int cardSuit, int cardFace)
{
this.suit = cardSuit;
this.face = cardFace;
this.faceup = false;
}
public int getSuit()
{
return this.suit;
}
public int getFace()
{
return this.face;
}
public int getValue()
{
int value;
if( this.face >= 10 )
value = 10;
else
value = this.face;
return value;
}
public boolean isFaceUp()
{
return this.faceup;
}
public void turnFaceUp()
{
this.faceup = true;
}
public void turnFaceDown()
{
this.faceup = false;
}
public String toString()
{
String cardname = "";
String suitname = "";
if(this.suit == 0)
suitname = "Spades";
if(this.suit ==1)
suitname = "Hearts";
if(this.suit ==2)
suitname = "Clubs";
if(this.suit ==3)
suitname = "Diamonds";
if(this.face == 1 || this.face > 10)
{
String facename = "";
if(this.face == 1)
facename = "Ace";
if(this.face == 11)
facename = "Jack";
if(this.face == 12)
facename = "Queen";
if(this.face == 13)
facename = "King";
cardname = facename + " of " + suitname;
}
else if(this.face != 1 && this.face <= 10)
cardname = this.face + " of " + suitname;
return cardname;
}
}

Deck


public class Deck
{
private Card[] cards;
private int cardsInDeck;
public static final int DECK_SIZE = 52;
public Deck()
{
cards = new Card[DECK_SIZE];
cardsInDeck = DECK_SIZE;
for (int i = 0; i < 13; i++)
{
cards[i] = new Card(i + 1, Card.HEARTS);
cards[i + 13] = new Card(i + 1, Card.DIAMONDS);
cards[i + 26] = new Card(i + 1, Card.CLUBS);
cards[i + 39] = new Card(i + 1, Card.SPADES);
}
}
public int cardsInDeck()
{
return cardsInDeck;
}
public Card deal()
{
if (cardsInDeck == 0)
throw new EmptyDeckException();
cardsInDeck--;
return cards[cardsInDeck];
}
public void shuffle()
{
int newI;
Card temp;
Random randIndex = new Random();
for (int i = 0; i < cardsInDeck; i++)
{
newI = randIndex.nextInt(cardsInDeck);
temp = cards[i];
cards[i] = cards[newI];
cards[newI] = temp;
}
}
public void reset()
{
cardsInDeck = DECK_SIZE;
}
public String toString()
{
if (cardsInDeck == 0)
return "<empty>";
String s = cards[0].toString() + ' ';
for (int i = 1; i < cardsInDeck; i++)
{
if (i % 13 == 0)
s += ' ';
s += cards[i].toString() + ' ';
}
return s;
}
}