COMP 14 Spring 2004

Program 4: Making Playing Cards

75 points

Assigned: Monday, March 23
Due: Monday, March 30 at 11:59pm

Description

This program is the first 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 4, you will create a Card class to represent a standard playing card, create several Card objects in an array, and total the Blackjack points for the cards (more details below).

A standard playing card has a suit and a face value. The suits are Spades, Clubs, Diamonds, and Hearts. The face values are 2-10, Jack, Queen, King, and Ace. The 52 cards in a standard deck are the result of having one face value in each suit (13 faces * 4 suits = 52 cards).

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 (and sometimes against other players). 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"). You are dealt two cards initially, and based on their point value, you can ask for additional cards one at a time (called a "hit") or stop receiving cards (called a "stand").

Program 4 Tasks

You will be given an outline of the files needed to complete this assignment (see "What to Do").

Modify the given class called Card that represents a standard playing card. You must include a constructor that initializes the values of the member variables, a toString method that returns a String representing the Card object, and getFace and getSuit methods that allow each of the member variables to be accessed.

Modify the given class called BlackjackGame that contains only the public static method calcPoints, which takes a Card object as a parameter and returns an integer representing the Blackjack point value of that card. For an Ace, calcPoints should return 11 points. Decisions on if the Ace should count as 11 points or 1 point will be determined in another piece of code.

Modify the given class called Blackjack that includes the main method and the public static method doProgram4. Inside main, you should create an array with 4 Card objects that represent the Ace of Spades, Queen of Hearts, 7 of Diamonds, and 2 of Clubs. Then, you should call the doProgram4 method with the array of cards as the parameter. Inside doProgram4, you should do the following:

Sample Output

Here is sample output using the cards specified in the description above. The TAs will grade your program based on this set of cards along with other sets of 4 cards. You should test your program with various combinations of cards.

Ace of Spades is worth 11 points
Queen of Hearts is worth 10 points
7 of Diamonds is worth 7 points
2 of Clubs is worth 2 points

>> Total points for this hand (before adjusting for Aces): 30
>> Total points for this hand (after adjusting for Aces): 20
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 Programs 5 and 6), you should create a new folder to hold the files. Name this folder something like Program4.
  3. For this assignment, you should have three classes (which means three Java source files). Name one Java source file Card.java and the class Card. Name the 2nd Java source file BlackjackGame.java and the class BlackjackGame. Name the 3rd Java source file Blackjack.java and the class Blackjack
  4. Copy Card.java into your Card.java file in jGRASP. Fill in the appropriate places (marked by "INSERT ... HERE").
  5. Copy BlackjackGame.java into your BlackjackGame.java file in jGRASP. Fill in the appropriate places.
  6. Copy Blackjack.java into your Blackjack.java file in jGRASP. Fill in the appropriate places. Note that the file already contains your pledge statement, just add your name and recitation section.
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 correctly use the provided classes to complete the assignment. This includes (but is not limited to):
  3. [10] You must correctly create the 4 specified Card objects.
  4. [10] You must determine the correct Blackjack point value for each card in the calcPoints method.
  5. [10] You must print each of the 4 cards along with their individual Blackjack point values.
  6. [10] You must determine and print the point total of the cards before adjusting for Aces.
  7. [10] You must determine and print the point total of the cards after adjusting for Aces.
  8. [5] You must use meaningful variable names, which conform to the style guidelines and Java naming convention discussed in class.
  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: