Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 2 : Scoring a blackjack hand This exercise counts towards your mark for Assessment Task 2 ( Final Assignment ) . Make sure you

Task 2: Scoring a blackjack hand
This exercise counts towards your mark for Assessment Task 2(Final Assignment). Make sure you complete it by 11:59pm Sunday the 2nd of June to avoid any late penalties.
As an assessed task, it's important that you complete it on your own. Any code that you submit for this exercise must be composed entirely within this page. You must not submit code that you have obtained from peers or any other source. For details, please see An important warning in Everything you need to know about this subject.
This task will be difficult if not impossible to implement without using collections, which will be taught in Week 9. We recommend you skip this task until then.
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!

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

=+20.19. Let A ,., () = [IZ, - Z|

Answered: 1 week ago