Task :A blackjack dealer
Your job is to implement two classes:
BlackjackHand and BlackjackDealer
.
The BlackjackHand class
You have been provided an empty BlackjackHand class, within
which you must implement the following methods:
A constructor that accepts no parameters, and
results in an empty hand of cards that has a score of 0.
A add method,
which accepts an instance of Card and returns nothing. Calling
this method should result in the given card being added to the
hand, and the hand's score being updated.
A getSize method
which accepts no parameters, and returns the number of cards in
the hand.
A get method
which accepts an index as an int, and returns the card that is
at the given index. E.g. calling get(0) should return the first
card, get(1) should return the second, etc.
A getScore method
which returns the score of the hand. This score must be
calculated according to the rules described above in
Background > Scoring a blackjack hand. If
there are Aces in the hand, then this score must make the best use
of them to ensure the score is as high as possible without going
bust (unless going bust is unavoidable).
An isBust method
which returns true if the hand score is greater than
21, or false otherwise.
The BlackjackDealer class
You have been provided an empty BlackjackDealer class, within
which you must implement the following methods:
A constructor that accepts no parameters, and
results in a dealer that has an empty hand of cards, and is not
staying.
An isStaying method
which accepts no parameters, and returns true if the
dealer is currently staying, or false if not.
A getHand method
which accepts no parameters, and returns the dealers hand as an
instance of BlackjackHand.
A take method
which accepts a Card parameter, and returns
false if the dealer is unable to accept the card (i.e. if
they are staying or bust) or true if they do accept the card. If
the dealer can accept the card, then calling this method should
result in the given card being added to the dealer's hand, and the
dealer updating whether they are staying or not. Their decision to
stay or not must be based on the rules discussed above in
Background > The dealer.
A reset method
which accepts no parameters and returns nothing. Calling this
method will result in the dealer having an empty hand, and not
staying.
THE EXAMPLE CODE:
BlackjackDealer.java
public class BlackjackDealer {
//Your code here
}
BlackjackHand.java
public class BlackjackHand {
//Your code here
}
Runner.java
public class Runner {
public static void main(String args[]) {
Deck deck = new Deck() ;
deck.shuffle() ;
BlackjackDealer dealer = new BlackjackDealer() ;
while (!dealer.isStaying() &&
!dealer.getHand().isBust()) {
Card card = deck.takeFromTop() ;
System.out.println("Dealer has been dealt the " + card) ;
dealer.take(card) ;
if (dealer.getHand().isBust()) {
System.out.println("Dealer is bust with a score of " +
dealer.getHand().getScore()) ;
} else if (dealer.isStaying()) {
System.out.println("Dealer is staying with a score of " +
dealer.getHand().getScore()) ;
} else {
System.out.println("Dealer is still in with a score of " +
dealer.getHand().getScore()) ;
}
}
}
}
Runner.java
BlackjackDealer.java
5 9 + BlackjackHand.java BlackjackDealer.java Runner.java i public class Runner { 2 3 public static void main(String args[]) { 4 Deck deck = new Deck() ; 6 7 deck.shuffle(); 8 BlackjackDealer dealer = new BlackjackDealer(); 10 11 while (!dealer.isStaying() && ! dealer.getHand().isBust()) { 12 13 Card card - deck.takeFromTop(); 14 System.out.println("Dealer has been dealt the " card) ; 15 16 dealer.take (card) ; 17 18 if (dealer.getHand().isBust()) { 19 System.out.println("Dealer is bust with a score of " + dealer.getHand().getScore()); 20 } else if (dealer.isStaying()) { 21 System.out.println("Dealer is staying with a score of " + dealer.getHand().getScore()); 22 } else { 23 System.out.println("Dealer is still in with a score of " + dealer.getHand().getScore()); 24 } 25 26 27 } - }
+ Runner.java BlackjackHand.java BlackjackDealer.java 1 public class BlackjackDealer { 2 3 //Your code here 4 }
+ Runner.java BlackjackHand.java BlackjackDealer.java i public class BlackjackHand { 2 3 //Your code here 4 5 }
Task :A blackjack dealer Your job is to implement two classes: BlackjackHand and BlackjackDealer . The BlackjackHand cla
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am