COMP 14 Spring 2004

Program 5: Blackjack Solitaire

75 points

Assigned: Wednesday, March 30
Due: Friday, April 8 at 11:59pm

Description

This program is the second in a three-part series that will result in a GUI-based Blackjack game. (A demo of the FINAL project is at http://www.cs.unc.edu/~stough/teaching/COMP14-S05/demo/blackjack_demo.html.)

In Program 5, you will allow the user to play a GUI-based Blackjack game alone (with no other players or dealer). A demo of Program 5 is at http://www.cs.unc.edu/~stough/teaching/COMP14-S05/demo/program5demo/prog5demo.html.)

See the Program 4 instructions for a refresher on the rules of Blackjack.

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 player's hand and the cards and the current point total should be displayed. The Deal button will change to Hit, and the Stand button will become enabled.





If you click Hit, the card from the top of the deck should be added to the current hand and the card and the new total point value displayed.

If the point total is Blackjack or a bust (over 21) or there are now 5 cards in the hand, the Hit button will change to Deal, the Stand button will be grayed out, and the turn will be over.
 
 

If you click Stand, the Hit button will change to Deal, the Stand button will be grayed out, and the turn will be over.





The user interface logic (graying out the buttons and displaying the cards) has been provided for you. Your main jobs are to implement the Deck and Hand classes and to write the logic needed to add cards to the player's hand and calculate the current point total.

Program 5 Tasks

You will be given an outline of the files needed to complete this assignment (see "What to Do"). You will have a total of 7 classes in this program. Each one is described below:

What to Turn in 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 using classes with these same names in Program 6), you should create a new folder to hold the files. Name this folder something like Program5.
  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. Save and unzip img.zip into your Program5 folder. After doing this you should see a folder called img in your Program5 folder that contains files such as 0.gif, 1.gif, ..., 53.gif. Files 1.gif - 52.gif each contain the image of a different playing card. File 0.gif contains the image of a face down card, and file 53.gif contains the image of a blank card (it's a placeholder).
  5. Copy Blackjack.java into your Blackjack.java file in jGRASP. This file already contains your pledge statement, you only need to add your name and recitation section.
  6. Copy BlackjackUI.java into your BlackjackUI.java file in jGRASP. You should not make any changes to this file.
  7. Copy BlackjackApplet.java into your BlackjackApplet.java file in jGRASP. You should not make any changes to this file.
  8. Copy your completed Card.java from Program 4 into your Card.java file in jGRASP. Change the assignment from "Program 4" to "Program 5".
  9. Copy Deck.java into your Deck.java file in jGRASP. Fill in the appropriate places as described above.
  10. Copy Hand.java into your Hand.java file in jGRASP. Fill in the appropriate places as described above.
  11. Copy your completed BlackjackGame.java from Program 4 into your BlackjackGame.java file in jGRASP. Change the assignment from "Program 4" to "Program 5". Add the constant, variables, and methods as described above.
Extra Credit

If you use the BlackjackApplet class to create an applet version of your program (applets let you run your programs over the web -- we'll talk more about them later), you can receive 10 extra credit points. Here's what to do:

To get credit for completing the extra credit, put the web address (URL) of your applet in the Blackboard comments section when you turn in your assignment.

Requirements

When the TA runs/examines your program, it must satisfy the following requirements. 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 from the top of the deck when the Deal button is pressed (i.e., when setupNewHand is called).
  3. [10] You must determine the current point total for the hand each time a new card is added (i.e., when calcPoints is called). This includes adjusting the total for the presence of Aces when necessary.
  4. [10] You must add a card from the top of the deck to the player's hand each time the Hit button is pressed (i.e, when addPlayerCard is called).
  5. [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 5 cards).
  6. [10] You must correctly determine when the player is eligible to ask for another card.
  7. [10] You must implement all of the methods that have been specified above.
  8. [5] You must use variables and methods with meaningful names.
  9. [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: