Substitute for Post Lab 9!!!

Due Friday, November 12, 2005

Your next programming project will be to write a program that plays a simplified game of Blackjack. (Details will be given in class Wednesday.) Instead of a post lab this week, you will write and test two of the classes you will need for the assignment.

There are two players in Blackjack, one of which is called the dealer and the other we will just call the player. Each player starts out with a hand of two cards. The value of the hand, often called the count, is what is of interest in the game. The player can go first and gets to decide whether to take another card (hit) or not (stick). The player can "hit" as many times as he/she wishes. The goal is to get as close to a count of 21 as possible without going over. Going over is called busting.

In real blackjack, an ace can count as a 1 or 11. For now just count an ace as a 1, the numbered cards as the number on the card, and the face cards as 10. (If you have time you can go ahead and think about how you would count the ace as either a 1 or 11.)

Do the following:

  1. Type in the Card class discussed in class. A description is in the file Card.html.

  2. Write a Hand class to model a Blackjack hand. Use the Card class to represent the cards. Note that the hand starts out with two cards. The main "action" associated with a hand is hitting so your class needs to be able to simulate a hit - that is, to add a card. The new card doesn't literally need to be added to the hand (you don't know how to do that yet and it isn't necessary). Instead it just needs to be printed and its points added to the total count for the hand. Think carefully about what instance variables you want for the class and what methods should be provided.

  3. Write a simple driver program to test your classes. It should instantiate a hand, print the initial hand, and then have a loop to keep hitting so you can be sure that method is working right (printing the new card and the new count).