Write a method named blackjack
that accepts as its parameter a Scanner
for an input file containing a hand of playing cards, and returns the point value of the hand in the card game Blackjack.
A card has a rank and a suit. There are 13 ranks: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King. There are 4 suits: Clubs, Diamonds, Hearts, and Spades. A Blackjack hand's point value is the sum of its cards' point values. A card's point value comes from its rank; the suit is irrelevant. In this problem, cards are worth the following points:
Rank |
Point Value |
2-10 |
The card's rank (for example, a 7 is worth 7 points) |
Jack (J ), Queen (Q ), King (K ) |
10 points each |
Ace (A ) |
11 points (for this problem; simplified compared to real Blackjack) |
The input file contains a single hand of cards, each represented by a pair of " " tokens. For example:
5 Diamonds
Q Spades
2 Spades 3 Hearts
Given the above input, your method should return 20, since the cards' point values are 5 + 10 + 2 + 3 = 20.
The input can be in mixed casing, have odd spacing between tokens, and can be split across lines. For example:
2 Hearts
j SPADES a Diamonds
2 ClUbS
A
hearts
Given the above input, your method should return 36, since the cards' point values are 2 + 10 + 11 + 2 + 11 = 36.
You may assume that the Scanner
contains at least 1 card (two tokens) of input, and that no line will contain any tokens other than valid card data. The real game of Blackjack has many other rules that you should ignore for this problem, such as the notion of going "bust" once you exceed a score of 21.