Due: 2024-10-28 23:59:00EDT
In this project you will be implementing BlackJack based on the description below.
Requirements:
- Use
printf
. You are not allowed to use any other method for printing output- Every method should be properly documented using the java doc notation.
- Every java file should have a header. However, DO NOT PUT YOUR NAME IN YOUR HEADERS. On gradescope we grade your assignments anonymously so including your name in your Java file will defeat that purpose. However, please include your name in your README.txt Note, in the examples,
*
indicates user input.
You are allowed to use the code we developed in class for 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:
$ 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!
$ 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!
$ javac BlackJack.java; java BlackJack
One of the dealer's cards is 11
Your hand's value is 22.
You lost - goodbye!
$ 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!
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.
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.
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!
Math.random()
generates a random value between 0 and 1. Use this
to create the value of a random card. The value of a card ranges from 1 to 11 (inclusive).In a text file called README.txt
answer the following questions:
Dont forget: make sure to fill in the header in all of your java files.
Submit the following files to the assignment called HW06
on Gradescope:
BlackJack.java
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.