Blackjack (Console-based)

Write a simplified, console-based version of Blackjack that allows a human user to play a single hand of the game against a computer dealer, with the following rules:

  • The hand that has value closest to but not exceeding 21 wins. In the case of a tie, the dealer wins.
  • The value of a hand is the sum of the individual values of the cards it contains.
  • Cards with rank 2 through 10 have a value equal to their rank
  • Face cards (i.e., jacks, queens, and kings) have a value of 10
  • An ace can be valued at either 1 or 11. The ace will be be given a value of 11, unless that causes the value of the hand to exceed 21.
  • Two cards are initially dealt to the dealer (one of which is hidden from the human player)
  • Two cards are initially dealt to the person playing the game (both visible to the human player).
  • After being dealt his hand, the human player is asked, based on the cards he can see, if he wants a "hit" (i.e., another card). If he does, another card is added to his hand.
  • The human player can continue to take additional "hits" if he wishes. If the value of the player's hand exceeds 21 at any time, he "busts" and loses the hand.
  • After the human player had stopped taking hits, and presuming the human player did not bust, the dealer may take some number of hits as well. The dealer will take hits as long as the value of his hand is less than 17. If the value of the dealer's hand exceeds 21 at any time, he "busts" and the human player wins the hand.
  • Presuming both the dealer and human player did not bust, the values of their hands are compared and a winner is declared.

The source code for this game should be comprised of four files: BlackjackGame.java, Hand.java, Deck.java, Card.java

Sample runs:

dealer's cards:
===============
<unknown card>
8 of Hearts

your cards: 
===========
3 of Hearts
2 of Spades

Do you want a hit? (Type "yes" or "no")
yes
You were dealt the 9 of Diamonds
Do you want a hit? (Type "yes" or "no")
yes
You were dealt the 4 of Hearts
Do you want a hit? (Type "yes" or "no")
no
The dealer asked for a hit and was dealt the Jack of Spades
The dealer's hidden card was the 6 of Clubs
The dealer busted.  You Win! :o)
dealer's cards:
===============
<unknown card>
8 of Hearts

your cards: 
===========
Ace of Clubs
7 of Hearts

Do you want a hit? (Type "yes" or "no")
no
The dealer asked for a hit and was dealt the 9 of Clubs
The dealer's hidden card was the 5 of Hearts
The dealer busted.  You Win! :o)
dealer's cards:
===============
<unknown card>
Ace of Clubs

your cards: 
===========
10 of Clubs
7 of Spades

Do you want a hit? (Type "yes" or "no")
no
The dealer's hidden card was the 7 of Diamonds

The dealer had 18
You had 17
You lose!
dealer's cards:
===============
<unknown card>
King of Spades

your cards: 
===========
8 of Spades
King of Clubs

Do you want a hit? (Type "yes" or "no")
no
The dealer's hidden card was the Queen of Diamonds

The dealer had 20
You had 18
You lose!
dealer's cards:
===============
<unknown card>
7 of Diamonds

your cards: 
===========
10 of Spades
4 of Spades

Do you want a hit? (Type "yes" or "no")
yes
You were dealt the 2 of Diamonds
Do you want a hit? (Type "yes" or "no")
yes
You were dealt the 4 of Clubs
Do you want a hit? (Type "yes" or "no")
no
The dealer asked for a hit and was dealt the 8 of Spades
The dealer's hidden card was the 6 of Clubs

The dealer had 21
You had 20
You lose!
dealer's cards:
===============
<unknown card>
Jack of Spades

your cards: 
===========
Queen of Diamonds
Jack of Hearts

Do you want a hit? (Type "yes" or "no")
no
The dealer asked for a hit and was dealt the 2 of Diamonds
The dealer asked for a hit and was dealt the King of Diamonds
The dealer's hidden card was the 3 of Clubs
The dealer busted.  You Win! :o)
dealer's cards:
===============
<unknown card>
4 of Spades

your cards: 
===========
2 of Diamonds
5 of Spades

Do you want a hit? (Type "yes" or "no")
yes
You were dealt the Queen of Spades
Do you want a hit? (Type "yes" or "no")
yes
You were dealt the King of Hearts
BUST! You lose.
dealer's cards:
===============
<unknown card>
9 of Diamonds

your cards: 
===========
10 of Diamonds
Jack of Hearts

Do you want a hit? (Type "yes" or "no")
no
The dealer's hidden card was the 8 of Hearts

The dealer had 17
You had 20
You win!
dealer's cards:
===============
<unknown card>
2 of Spades

your cards: 
===========
Ace of Clubs
8 of Clubs

Do you want a hit? (Type "yes" or "no")
no
The dealer asked for a hit and was dealt the Ace of Spades
The dealer asked for a hit and was dealt the 3 of Diamonds
The dealer asked for a hit and was dealt the 8 of Diamonds
The dealer's hidden card was the 9 of Hearts
The dealer busted.  You Win! :o)
dealer's cards:
===============
<unknown card>
9 of Diamonds

your cards: 
===========
5 of Diamonds
King of Spades

Do you want a hit? (Type "yes" or "no")
yes
You were dealt the 6 of Hearts
Do you want a hit? (Type "yes" or "no")
no
The dealer's hidden card was a Jack of Spades

The dealer had 19
You had 21
You win!