COMP 14 Spring 2004

Program 6: Blackjack

100 points

Assigned: Wednesday, April 6
Due: Wednesday, April 20 at 11:59pm

Goal

This is our final program of the semester. By completing this assignment, you will have demonstrated your ability to design and implement a solution to a problem using the programming constructs that you have learned throughout the semester. Additionally, because one of the requirements of this assignment is to create an applet version of Blackjack, you will be able to share your finished project with friends and family via the Internet.

Description

This program is the third in a three-part series resulting in a GUI-based Blackjack game that a user can play against the dealer. A demo of the final project (Program 6) is at http://www.cs.unc.edu/~stough/teaching/COMP14-S05/demo/blackjack_demo.html.

Report

25 points of this assignment will be given based on a written report. Your report should be written in HTML, put in your webspace, and contain a description of the Card, Deck, and Hand classes and how these classes work together. Your report should also describe the logic used in scoring the Blackjack hand. Finally, your report should contain questions, comments, or interesting things you learned while working on this project (including Programs 4-6).
Maximum length: 300 words

Blackjack

In Blackjack, the points for numerical face values are the same as the face value (e.g., the 5 of Diamonds is worth 5 points). Jack, Queen, and King cards are worth 10 points each. Ace cards are worth either 11 points or 1 point, depending on the situation.

Blackjack is usually played against a dealer. The object of the game is to have the group of cards (called a "hand") which has the closest point total to 21 (called "Blackjack") without going over (called a "bust").

In a game against the dealer, the player is initially dealt two cards face-up and the dealer is dealt two cards, the 2nd of which is dealt face-down. The player can then decide to ask for additional cards one at a time (called a "hit") or stop receiving cards (called a "stand").

If the player "busts", the dealer automatically wins. Otherwise, once the player has decided to "stand", the dealer plays out the hand. If the dealer's hand point total is less than 17, the dealer must "hit". If the dealer's hand point total is 17 or greater, the dealer must "stand".

If the dealer "busts", the player automatically wins. Otherwise, once the dealer has decided to "stand", the winner is determined. The winner has the hand closest to Blackjack (21). A tie results if both the player and the dealer have the same number of points.

In our game, there are a maximum of 5 cards that can be dealt to either the player or the dealer. This is due to limitations in the user interface. Once the player or the dealer has 5 cards, they are not allowed to "hit".

Sample Output

When you start the program, a blank table with buttons will be displayed:



After clicking Deal, the top 2 cards from the deck will be added to the dealer's hand, and the cards will be displayed (the 2nd card will be shown face-down), along with the point total of the visible card. Then, the next 2 cards from the deck will be added to the player's hand, and the cards and the current point total of the player's hand will be displayed. The Deal button will change to Hit, and the Stand button will become enabled.



If the player clicks Hit, the card from the top of the deck will be added to the player's hand, and the card and the new total point value will be displayed. If the point total is Blackjack or a bust (over 21) or there are now 5 cards in the player's hand, the Hit button will change to Deal, the Stand button will be grayed out, and the player's turn will be over. If the player did not bust, the dealer will play out the hand according to the rules given above. The dealer's cards and final point total will be revealed. Finally, the tally of player wins, losses, and ties will be updated depending on who won the game.



If the player clicks Stand, the Hit button will change to Deal, the Stand button will be grayed out, and the player's turn will be over. The dealer will then play out the hand according to the rules given above. The dealer's cards and final point total will be revealed. Finally, the tally of player wins, losses, and ties will be updated depending on who won the game.

The user interface logic (graying out the buttons, displaying the cards, point value, and tally) has been provided for you. Your main jobs are to control the dealer's hand, player's hand, calculate the point value for a hand, and tally the total wins, losses, and ties.

User Interface Operation

When the Deal button is pressed, the user interface will call the following methods from your code (see the dealButtonPressed method in BlackjackUI.java for details):

When the Hit button is pressed, the user interface will call the following methods from your code (see the hitButtonPressed method in BlackjackUI.java for details): When the Stand button is pressed, the user interface will call the following methods from your code (see the standButtonPressed method in BlackjackUI.java for details): When the player is done with their hand, the playerDone method in BlackjackUI will be called. This method will call the following methods from your code (see the playerDone method in BlackjackUI.java for details): In addition to these, BlackjackGame.initGame is called from the main method in Blackjack.java and from the init method in BlackjackApplet.java.

Program 6 Tasks

As with Program 5, you will have a total of 7 classes in this program. Each one is described below:

Making an Applet What to Do
  1. Follow the directions for completing programming assignments.
  2. Since this assignment will contain multiple Java source files (and we will be used classes with these same names in Program 5), you should create a new folder to hold the files. Name this folder something like Program6.
  3. For this assignment, you should have seven classes (which means seven Java source files): Card.java, Deck.java, Hand.java, BlackjackGame.java, BlackjackUI.java, BlackjackApplet.java, and Blackjack.java.
  4. Copy your img folder from your Program5 folder into your Program6 folder.
  5. Copy your completed Card.java from Program 5 into your Card.java file in jGRASP. Change the assignment from "Program 5" to "Program 6".
  6. Copy your completed Deck.java from Program 5 into your Deck.java file in jGRASP. Change the assignment from "Program 5" to "Program 6".
  7. Copy your completed Hand.java from Program 5 into your Hand.java file in jGRASP. Change the assignment from "Program 5" to "Program 6".
  8. Copy your completed Blackjack.java from Program 5 into your Blackjack.java file in jGRASP. Change the assignment number, due date, description, input, and output to reflect the current assignment.
  9. Copy BlackjackUI.java into your BlackjackUI.java file in jGRASP. You should not make any changes to this file.
  10. Copy BlackjackApplet.java into your BlackjackApplet.java file in jGRASP. You should change only the IMG_URL constant (as described above in "Making an Applet").
  11. Copy your completed BlackjackGame.java from Program 5 into your BlackjackGame.java file in jGRASP. Change the assignment from "Program 5" to "Program 6". Make the changes described above.
  12. Once your program is working from jGRASP, follow the instructions for making an applet that are given above. Put the web address (URL) of your applet in the Blackboard comments section when you turn in your assignment.
  13. Using Notepad, write your report in HTML and save it as "report.html". Copy this file to your web space in your public_html/Blackjack folder in AFS space. Put the web address (URL) of your report in the Blackboard comments section when you turn in your assignment. Do not use any web design software (including Microsoft Word) to write your report. Check your report by going to http://www.unc.edu/~onyen/Blackjack/report.html
What to Turn in Requirements

When the TA runs/examines your program, it must satisfy the following requirements (which are in addition to the requirements from Program 5). The maximum point value for each is shown in brackets.

  1. [5] Your Java source files, classes, and Jar file must be appropriately named (as specified above).
  2. [10] You must add two cards to the player's hand and two cards to the dealer's hand from the top of the deck when the Deal button is pressed (i.e., when setupNewHand is called).
  3. [10] You must re-shuffle the deck when there are not enough cards available for an entire turn to be played (an entire turn may require dealing at most 10 cards).
  4. [10] You must correctly play out the dealer's hand after the player has decided to stand.
  5. [10] You must correctly determine the winner.
  6. [10] You must keep track of the total number of wins, losses, and ties.
  7. [10] You must create an applet version of your program and provide the URL when submitting your assignment.
  8. [25] You must write a report in HTML (without using web design or authoring software) and provide the URL when submitting your assignment.
  9. [5] You must use variables and methods with meaningful names.
  10. [5] You must comment your code, including block-like multi-line comments and single-line comments where appropriate. In addition, your code must be neatly and clearly formatted using appropriate "white space."
Notes: