Java Bootcamp – Workbooks and Challenges


Blackjack is the most popular table game at casinos. You're going to build a simple version of Blackjack.

Part 1: Starting the game

  • In Blackjack, the player plays against the dealer.

  • The dealer gives the player two cards faceup.

  • The dealer also starts with two cards. But, only one of the dealer's cards is faceup. The other is facedown.

Part 2: During the game

  • First, it's the player's turn. The player can decide to hit or stay.

    • hit: draw another card.

    • stay: do nothing.

  • If the player decides to hit, and their hand value exceeds 21, they go bust (lose).

  • Once the player decides to stay, the dealer reveals the hidden card.

  • Then, the dealer must hit until their cards total up to 17. At 17 points or higher, the dealer must stay.

  • You win if your hand value is higher than the dealer's hand.

  • You win if the dealer goes bust (exceeds 21)

  • You lose if the dealer's hand value is higher than yours.

Full output:

Launch the challenge

From Java Bootcamp Resources -> Module 1 -> 5. Loops, open Challenge 5.

Task 1

Define the drawRandomCard function.

/** * Function name -- drawRandomCard * @return (int) * * Inside the function: * 1. Gets a random number between 1 and 13. * 2. Returns a card. */

Task 2

Make a function that receives a card number and returns the String drawing. You can grab the cards from cards.txt. Use the doc comment inside the workbook as a guide.

Task 3

Write code that waits for the user to press enter.

Task 4

When the game starts, the dealer will give you two cards faceup. Get the code to deal you two random cards and print them:

-- Get two random cards.
-- Print them: (new line) You get a (new line) <random card> and a <random card>

Task 5

After you print your cards, print the hand value. The hand value is the sum of your card values.

your total is: <hand value>

In blackjack, the face cards (Jack, Queen, and King) have values of 10.

Hint: look into Math.min.

Example output:

Task 6

The dealer gets two cards as well. Print the dealer's first card, and print the next one facedown. You can find the String for a facedown card being returned from a function called: faceDown().

1. print:

 (new line) The dealer shows (new line) <random card> and
 has a card facing down (new line) <facedown card>;

2. print:
 (new line) The dealer's total is hidden

That's all for part 1. Your final output should appear as follows:

Good luck!

Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer

Feedback Summary
43 students





Written Reviews
There are no written reviews yet.