CPSC 120 Assignment #4
Blackjack with Classes
Part I Due, Friday November 21, 2008 by 4 p.m.
In this assignment you will write a program that plays the game
of Blackjack. The main idea of Blackjack
is to get a hand of cards that adds up as close as possible to 21 without
going over. We will use the following rules:
- There are two players. One is called the dealer and has
very strict rules for how to play; the other we'll call the player.
- At the beginning of the game, each player gets two cards. The player
gets to see both of his or her cards. One of the dealer's cards (called
the top card) is shown.
- The value of a hand, called the "count",
is the sum of the face values of the cards.
Face cards (Jack, Queen, King)
have a value of 10. The ace can have a point value of 11 or 1. Generally it
is an 11 unless that makes the total count go over 21. When the count
includes an ace that has been counted as an 11 the count is called
soft. If a new card is dealt that puts the count over 21 and if the
current count is soft 10 points are deducted (in other words the ace
counts only 1) adn the count is no longer soft. In most games the dealer
always uses a soft count; that is, the ace is always valued at 11.
- After the hands are dealt, the player goes first. If the player was
dealt blackjack (an ace and a card valued at 10 points) but the dealer was not,
the player wins and the game is over. If both the dealer and the player
are dealt blackjack, the game is a tie. Otherwise, the player gets to decide
whether to hit or stick (some people say "stand" and some say "stay"). Hit
means get another card; stick means to stop taking cards. The player
can keep taking cards (hitting) until he/she decides to stay or busts (goes
over 21 points).
- If the player busts, he/she loses and the game is over.
- If the player does not bust, it is the dealer's turn.
- The dealer has strict rules that determine when to hit and when to
stick. If the current count (total value of the hand) is 16 or less, the
dealer hits. On a count of 17 or more, the dealer sticks. If the dealer
busts, the player wins. If the dealer does not bust, the two hand counts
are compared and the highest one wins. If the counts are the same it
is a tie.
Your basic program for Part I of the assignment will play the
game between a human player and a dealer. It should ask for the name
of the player, then have a loop that lets the player keep playing
games against the dealer. It should clearly indicate what is happening
as the game is played (it must show the initial cards for the human
player, it must display the "top" card for the dealer, and each
time a player hits it should display the new card and the new point
total).
Sample output:
Welcome to the Blackjack Casino!
===============================
Please enter the player's name: Bozo
Dealing Bozo's hand...
Cards are 3 of Diamonds and 5 of Hearts
Count is 8
Dealing Dealer's hand...
Top card is 10 of Clubs
Bozo's turn...
Do you want to hit or stick (h or s)? h
New card is 6 of Clubs
Count is 14
Do you want to hit or stick (h or s)? h
New card is Ace of Spades
Count is 15
Do you want to hit or stick (h or s)? h
New card is 4 of Hearts
Count is 19
Do you want to hit or stick (h or s)? s
Dealer's turn...
Bottom card is 4 of Diamonds
Count is 14
Dealer hits...
New card is 3 of Spades
Count is 17
Dealer sticks...
Bozo's count is 19
Dealer's count is 17
Bozo wins!
Play again?
....
Additional requirements:
- Your program must be in a package named assign4 in your
Assignments directory.
- Follow the specifications for the classes as posted on the
course web page (after the design exercise in class).
- Use good programming style -- meaningful variable names, named constants,
use of white space, proper indentation.
- Document your program. Each class must have header documentation
at the top that includes a description of the purpose of
the program or class (for a class it should be what "objects" it
represents) and your name.
Each method must have documentation (use Eclipse
to generate JavaDoc) that includes the clear description of the
purpose of the method, a description
of each parameter, and a description of what is returned by the method
(if it is not void).
Have internal documentation where necessary that delineates and succinctly
(and clearly) indicates what each section is doing.
Grading
Your program will be graded both on style and correctness. Style includes
adherence to rules for naming of identifiers and use of white space; it
also includes coding style such as the absence of unnecessary code (extra
comparisons in if's or extra assignments); it includes good class
design (appropriate choice of instance variables and methods);
it includes appropriate
documentation. Style will be 20% of the grade on the assignment.
Correctness includes meeting all the specifications of the assignment.
A program that does not compile has an automatic deduction of 70%
no matter how "close"
it is to compiling or running. Come see me if you have problems
with the assignment. It is important that you get in the habit of
producing correct programs!
NOTE: Part II of the assignment will be to add the capability
of the player being a computer.
Academic Integrity Reminder!!! Programming
assignments are to be your own work. You may get help on the specifics
of the assignment from no one except the instructor. You may not show
your program to anyone or look at anyone else's program or share ideas
with anyone about how to write the program.
Hand IN: A printed copy of your program files.
Tar your assign4 directory and email the tar file
to your instructor.