Answered step by step
Verified Expert Solution
Link Copied!

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 2 of hearts is worth 2 points, a 7 of diamonds is worth 7 points, etc.
Each of the face cards Jack, Queen and King are worth 10 points.
The ace is worth either 1 point or 11 points (the player is free to choose).
The objective is to get a hand with a score that is as close as possible to 21, without going over. If the player gets a score that is over 21, 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 1. 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 21 on the draw:
Starting Hand:[A, J] Score:21
Going bust without any aces
Starting Hand:[3,7] Score:10
Hand:[3,7,6] Score:16
Hand:[3,7,6,10] Score:26
Bust!
Getting 21 with an ace
Starting Hand:[A,4] Score:15
Hand:[A,4,4] Score:19
Hand:[A,4,4,2] Score:21
Going bust with an ace
Starting Hand:[6, A] Score:17
Hand:[6, A,7] Score:14
Hand:[6, A,7,3] Score:17
Hand:[6, A,7,3, K] Score:27
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 21, 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions