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:
-
print each Card object and its Blackjack point value to the user
-
total the point values of the 4 cards and display that total to the user
-
adjust the total for Aces
-
as long as the total point value is greater than 21 (Blackjack), adjust
the total so that Aces (if there are any Aces in the group of cards) count
as 1 point instead of 11 points
-
the total should still be as close to 21 as possible (i.e., there
could be a situation where not all of the Aces in the group of cards should
count as 1 point instead of 11 points)
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
-
Your prog4_onyen.jar file (where onyen is your Onyen), which
includes your Card.java, BlackjackGame.java, and Blackjack.java source
files
-
short write-up of questions you had and/or problems you encountered while
doing this assignment
What to Do
-
Follow the directions for completing programming
assignments.
-
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.
-
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
-
Copy Card.java into your Card.java
file in jGRASP. Fill in the appropriate places (marked by "INSERT ... HERE").
-
Copy BlackjackGame.java
into your BlackjackGame.java file in jGRASP. Fill in the appropriate places.
-
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.
-
[5] Your Java source files, classes, and Jar file must be appropriately
named (as specified above).
-
[10] You must correctly use the provided classes to complete the assignment.
This includes (but is not limited to):
-
using the constants that have been provided
-
implementing code for all of the methods that have been specified
-
only using System.out.print() or System.out.println()
inside the Blackjack class and not in the Card or BlackjackGame classes
-
[10] You must correctly create the 4 specified Card objects.
-
[10] You must determine the correct Blackjack point value for each card
in the calcPoints method.
-
[10] You must print each of the 4 cards along with their individual
Blackjack point values.
-
[10] You must determine and print the point total of the cards before
adjusting for Aces.
-
[10] You must determine and print the point total of the cards after
adjusting for Aces.
-
[5] You must use meaningful variable names, which conform to the style
guidelines and Java naming convention discussed in class.
-
[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:
-
If your program doesn't compile or run (i.e., has a syntax error), you
will receive 0 credit for the items listed above in bold (so, at most 45/75
points).
-
Remember that an implicit requirement for all assignments is that your
code must include (at the top) the standard
program header with pledge, and your signed pledge must be on file.