Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this task you will implement a Scorer class for scoring a hand of blackjack, and deciding if it is bust or not. Background In
In this task you will implement a Scorer class for scoring a hand of blackjack, and deciding if it is bust or not.
Background
In blackjack, the score of a player is determined by their hand of cards. More specifically, it's determined by the ranks of their cards suits have no effect on scores :
Each numeric card is worth the same as the card's rank. For example, a of hearts is worth points, a of diamonds is worth points, etc.
Each of the face cards Jack, Queen and King are worth points.
The ace is worth either point or points the player is free to choose
The objective is to get a hand with a score that is as close as possible to without going over. If the player gets a score that is over they go "bust" and loose the round.
Specification
The Scorer class must provide the following methods:
A static getScore method, which accepts a hand of cards as List of Card and returns the score of this hand. This score must be calculated according to the rules described in the Background section above. 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
A static isBust method, which accepts a hand of cards as List of Card and returns true if the hand is bust, or false if it is not. The logic for deciding whether a hand is bust is described in the Background section above.
Available classes and methods
Your workspace includes compiled versions of the Suit enum and the Card and Deck classes, all of which have been implemented exactly as specified in Task You won't be able to see the source code of these classes, but you can can and should use them in your solution. Refer back to the task description for details about how these classes work and which methods they have.
We have provided a Runner class with a main method that will be executed when you click the Run button. You are welcome to change this method however you like. This file is not used in testing and is provided purely to allow you to interact with and explore your own code.
Examples
Here are some examples of the output of the runner if you leave it unchanged, and implement the classes correctly:
Getting on the draw:
Starting Hand:A J Score:
Going bust without any aces
Starting Hand: Score:
Hand: Score:
Hand: Score:
Bust!
Getting with an ace
Starting Hand:A Score:
Hand:A Score:
Hand:A Score:
Going bust with an ace
Starting Hand: A Score:
Hand: A Score:
Hand: A Score:
Hand: A K Score:
Bust!
Hints
Expand
You can think of each ace in a hand as an opportunity to reduce the hand score if it would otherwise go bust. So you need to track how many times this opportunity can be taken for a hand, and reduce that count every time the opportunity is taken.
Expand
You are bust if your score is greater than so it makes sense for the isBust method to simply call the getScore method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started