A Round of Blackjack - JAVA
In this final task you will implement a game of blackjack
between a single player and an automated dealer.
Background
The previous task explained how blackjack hands are scored, and
how the dealer makes decisions. Let's now talk about how a round of
blackjack actually plays out. For the sake of simplicity, we will
focus on how the game works when there is only a single player, and
when the game only lasts for a single round, and when there are no
bets involved.
A round of blackjack with a single player involves the following
steps:
The initial deal
The dealer deals one card to the player, and then one to
themselves. These cards are all dealt face up (meaning that
everyone can see the cards).
The dealer then deals a second card to the player, and a second
one to themselves. The player's card is dealt face up, but the
dealer's one is played face down.
Resolving naturals
If the dealer's first card is an 10, jack, queen or king or ace,
they will privately look at their second card to see if they have a
natural pair (i.e. a pair of cards with a score that is exactly
21).
If the dealer does not have a natural pair, then play moves on
to the players turn.
Otherwise, play immediately stops. If both the player
and the dealer have natural pairs, the game ends in a tie. If only
the dealer has a natural pair, then the dealer wins.
The player's turn
The player chooses to hit or stay.
If they choose to stay, then play moves on to the dealers
turn.
If they choose to hit and go bust, then play immediately
stops and the dealer wins.
If they choose to hit and do not go bust, they again choose to
either hit or stay. They can continue to make this choice until
they eventually go bust or choose to stay.
The dealer's turn
The dealer follows the rules described in Task 2 for choosing
whether to hit or stay, and continue to follow these rules until
they either stay or go bust.
If after applying these rules the dealer is bust, then play
immediately stops and the player wins.
If the dealer is not bust, then their score is compared to the
player. Whoever has the highest score wins. If both player and
dealer have the same score, the round ends in a draw.
Task details
Your job is to implement the class Blackjack according to the
specification below.
Your workspace includes compiled versions of the Card, Deck,
BlackjackHand and BlackjackDealer classes, all of which have been
implemented exactly as specified in Tasks 1 & 2. You won't be
able to see the source code of these classes, but you can can (and
should) use them in your solution. Refer back to the task
descriptions for details about how these classes work and which
methods they have.
The Blackjack class
The Blackjack class has been created for you with:
A main method that you should not make any changes to
A play method that accepts an instance of Deck as the only input
parameter, and returns nothing.
Your job is to complete the play method, such that it results in
the user being able to play a single round of blackjack against an
automated dealer. You should get input from the user about whether
they want to stay or hit, but otherwise all play (i.e. dealing
cards, calculating scores, identifying winners and losers) should
be done automatically.
You must not shuffle or recreate the deck within the
play method. Your game must use the deck that is passed into the
method as it is provided, and simply remove cards from it using the
takeFromTop() method. You do not need to return cards to the deck
at the end of the round.
CODE SKELETON:
import java.util.Scanner ;
public class Blackjack {
//Do not alter this main method
public static void main(String args[]) {
Deck deck = new Deck() ;
deck.shuffle() ;
play(deck) ;
}
public static void play(Deck deck) {
//Your code here.
//Do not do anything with the deck
other than call deck.takeFromTop();
}
//Feel free to add any useful functions
also.
}
A Round of Blackjack - JAVA In this final task you will implement a game of blackjack between a single player and an aut
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
A Round of Blackjack - JAVA In this final task you will implement a game of blackjack between a single player and an aut
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!