a. In Chapter 10, you developed a Card class that contains a string data field to hold

Question:

a. In Chapter 10, you developed a Card class that contains a string data field to hold a suit and an integer data field for a value from 1 to 13. Now extend the class to create a class called BlackjackCard. In the game of Blackjack, each card has a point value as well as a face value. These two values match for cards with values of 2 through 10, and the point value is 10 for Jacks, Queens, and Kings (face values 11 through 13). For a simplified version of the game, assume that the value of the Ace is 11. (In the official version of Blackjack, the player chooses whether each Ace is worth 1 or 11 points.)

b. Randomly assign values to 10 BlackCard objects, then design an application that plays a modified version of Blackjack.  In this version, the objective is to accumulate cards whose total value equals 21, or whose value is closer to 21 than the opponent’s total value without exceeding 21. Deal five BlackjackCards each to the player and the computer. Make sure that each BlackjackCard is unique. For example, a deck cannot contain more than one Queen of Spades.
Determine the winner as follows:

  • If the player’s first two, first three, first four, or all five cards have a total value of exactly 21, the player wins, even if the computer also achieves a total of 21.
  • If the player’s first two cards do not total exactly 21, sum as many as needed to achieve the highest possible total that does not exceed 21. For example, suppose the player’s five cards are valued as follows: 10, 4, 5, 9, 2. In that case, the player’s total for the first three cards is 19; counting the fourth card would cause the total to exceed 21.
  • After you have determined the player’s total, sum the computer’s cards in sequence. For example, suppose the computer’s cards are 10, 10, 5, 6, 7. The first two cards total 20; you would not use the third card because it would cause the total to exceed 21.
  • The winner has the highest total among the cards used. For example, if the player’s total using the first three cards is 19 and the computer’s total using the first two cards is 20, the computer wins. Display a message that indicates whether the game ended in a tie, the computer won, or the player won.
Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: