Skip to main content

Homework : BlackJack (Extra Credit)

Due: 2024-10-28 23:59:00EDT

In this project you will be implementing BlackJack based on the description below.

Requirements:

You are allowed to use the code we developed in class for Blackjack.

BlackJack

Write a program called BlackJack.java that will allow a user to play a simplified version of BlackJack. The rules of BlackJack are as follows:

Example 1
$ javac BlackJack.java; java BlackJack
One of the dealer's cards is 5
Your hand's value is 12. What would you like to do:
*HIT*
Your hand's new value is 22. 
You lost - goodbye!
Example 2
$ javac BlackJack.java; java BlackJack
One of the dealer's cards is 10
Your hand's value is 13. What would you like to do:
*HIT*
Your hand's new value is 20. What would you like to do:
*STAY*
The dealer's hand is 19.
You won - congrats! 
Example 3
$ javac BlackJack.java; java BlackJack
One of the dealer's cards is 11
Your hand's value is 22. 
You lost - goodbye!
Example 4
$ javac BlackJack.java; java BlackJack
One of the dealer's cards is 9
Your hand's value is 5. What would you like to do:
*HiT*
Your hand's new value is 7. What would you like to do:
*hiT*
Your hand's new value is 11. What would you like to do:
*hit*
Your hand's new value is 18. What would you like to do:
*stAy*
The dealer's hand is 12.
The dealer's hand is 15.
The dealer's hand is 21.
You lost - goodbye!

2. Requirements

Multiple rounds

Your program must allow a user to play multiple rounds of Blackjack. The program must keep track of how many times the user has won and lost.

Your program must take in the number of rounds a user wants to play via a command line argument.

$java BlackJack 10

The above bash command runs the program and indicates that the user wants to play 10 rounds of Blackjack. If no command line argument is passed in or if the command line argument is not an integer, then the program will run for just one round of BlackJack.

Case-insensitive

Your program must be case-insensitive. That means that if a user inputs “Hit”, or “hit”, or “HIT”, then you give them another card (the same goes for “Stay”).

Lok at Example 4 to see how the program must accept “stAy” or “hiT” or “HiT” as valid options.

Robust to bad user input

If a user inputs something besides for Stay or Hit, then re-prompt the user for a valid answer. The example below demonstrates how your program should work:

$ javac BlackJack.java; java BlackJack
One of the dealer's cards is 5
Your hand's value is 12. What would you like to do:
*SHtay*
SHtay is invalid.
Your hand's value is 12. What would you like to do:
*hit*
Your hand's new value is 22. 
You lost - goodbye!

3. Hints

README.txt

In a text file called README.txt answer the following questions:

  1. How much time did you spend on the homework
  2. What did you learn from this homework
  3. optional: What did you struggle with during this homework
  4. optional: any other feedback you would like to share

Dont forget: make sure to fill in the header in all of your java files.

Submitting

Submit the following files to the assignment called HW06 on Gradescope:

  1. BlackJack.java
  2. README.txt

Make sure to name these files exactly what we specify here. Otherwise, our autograders might not work and we might have to take points off.