Rules of Blackjack For this assignment, you will implement a video card game. Th
ID: 3760879 • 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.
1. 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.
2. Write in a design document (text file) your general algorithm for how you would create a simple blackjack game main loop with wagering for two players (and the dealer). Describe your inputs and outputs as well as any error conditions that may occur. You should include when you would create objects and when you would call instance methods. Your algorithm should cover all of the rules listed above for the game of blackjack. You MAY include a flowchart to better describe your algorithm. You should (minimally) answer the following questions: a. What is the condition of the main loop? When does it stop? b. How do you figure out who has won? c. How do you calculate earnings/losses per player? d. How would your algorithm change to accommodate more than 2 players?
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.
Deck.java should be formatted similarily.
Explanation / Answer
card.java
public Card(int cardSuit, int cardFace){
suit=cardSuit;
face=cardFace;
}
public int getSuit(){
return suit;
}
public int getFace()
{
return face;
}
public int getValue()
{
return face;
}
Deck.java
public class Deck {
private Card[] mcards; // 52 cards an array name card
private int mcardsInDeck; //current number of card
public static final int DEK_SIZE = 52; //size of the card
public Deck() {
mcards = new Card[DEK_SIZE];
mcardsInDeck = DEK_SIZE;
for (int i = 0; i < 13; i++) {
mcards[i] = new Card(i + 1, Card.HEARTS);
mcards[i + 13] = new Card(i + 1, Card.DIAMONDS);
mcards[i + 26] = new Card(i + 1, Card.CLUBS);
mcards[i + 39] = new Card(i + 1, Card.SPADES);
}
}
public Card deal() {
if (mcardsInDeck == 0) // current number of card is empty
throw new EmptyDeckException();
mcardsInDeck--;
return mcards[mcardsInDeck]; // return the value.
}
public boolean isEmpty(){
return mcards.isEmpty(); //if card is empty.
}
public void shuffle() {
int newoneI;//delclare the variables
Card temp; // temp value
Random randIndex11 = new Random(); // declare the variable for random cards in deck
for (int i = 0; i < mcardsInDeck; i++)
{
newoneI = randIndex11.nextInt(mcardsInDeck); // random between value zero and -1
temp = mcards[i]; // holding cards as an array.
mcards[i] = mcards[newoneI]; // assign the values
mcards[newoneI] = temp;
}
}
} //end of class deck
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.