CS 101 (Spring 1999)
Lab 6: Java Jack

Lab Assigned Design Due
(Mondays 2 PM)
Lab Due
(Fridays 2 PM)
19 Feb 8 Mar 19 Mar


This lab is loosely based on the card game called Black Jack. A player tries to draw cards until the player's hand is worth as close to 21 points as possible, without going over. A numbered card, such as the 3 of Clubs, is worth its stated value, such as 3 points. A face card is wroth 10 points. An Ace is worth 1 or 11 points in Black Jack. For Java Jack, an Ace is worth 11 points if the player's hand has fewer than 3 cards; otherwise, the Ace is worth only one point.

You will implement both a customer and a dealer, that differ only in terms of how they decide to draw more cards. The dealer decides automatically based on the dealer's hand; the customer is under your control.


By the end of this lab, you should This lab contains two parts, design and implementation, due on the dates shown above by 2 PM.

The design will be discussed Monday in class. In Lab, your graded design will be returned. No other handouts or code will be issued. So, think carefully about your design!

Before starting:

[[[ Download PC zip ]]]
Zip includes: The MousePad and DirectionVector are from Lab 2 . Use of HandViz is optional and is worth extra credit if you use it to show the hands visually.

Remember to type the following lines at the top of any files that use the terminal or canvas classes.

import cs101.terminal.*;
import cs101.canvas.*;



Design and implement the class Card.java that represents a playing card. Conceptually, a playing card has a

However, from an implementation standpoint, we will encode a card using an integer id, where id is in the inclusive range 0...51. Let us assume that Thus, the following code
  Card c1 = new Card(15);
creates a card with id 15, which represents the 3 of Diamonds.

Within the Card class, we will need the following methods.


This object represents a linked-list of cards. Each card in the list is currently shown or not shown. Pattern your design of this class after the examples you have seen in class and in the notes (i.e., the wrap-and-link idea). For this class, you will need the following methods (include their API but not their implementation in your design):

Save yourself time: think about how you can write a method by calling other methods you have already written.


This class is provided to you for this lab. However, it won't work properly until your CardList and Card classes are implemented. This class has the following methods.

This constructor makes a new deck, with the cards in order.
void shuffle()
This method shuffles the (remaining) cards
Card draw()
This method removes and returns a card from the deck.

Customer and Dealer

Each of these classes must provide the following methods

What to turn in:

Design (due Monday)
  1. Complete a design cover sheet.
  2. Define your Card class.
    • Give its API and describe what the methods do.
    • How do you get a card's suit and rank?
    • How are these represented?
    • How do you get a card's point value?
    • Remember to keep instance variables as private as possible.
  3. The methods in the API for CardList are given. For your design, do the following.
    • Define the instance variables -- their names and purpose.
    • Draw an example of a 3-card CardList.
    • Where you can get away with it, explain how you will implement a method in terms of other methods in this class.
    • Sketch a loop that iterates through a given CardList.
  4. In terms of the methods you define for CardList, provide code for the Dealer's wantCard method, assuming
    • If the dealer has 16 or fewer points, then another card must be taken.
    • Otherwise, no more cards can be taken.
  5. Explain how the Customer class (as given) decides whether to want more cards or not.
Implementation (due Friday)
  1. Complete a code cover sheet.
  2. Provide a transcript from self-test of CardList and Dealer. Your testing must include coverage of all methods in CardList.
  3. Provide a transcript of 10 games played between the dealer and the customer.
  4. Provide printouts of any files you created or modified for this assignment.
  5. Be prepared to demo in lab.

Suggested implementation approach:

  1. Get Card working.
  2. Get enough of CardList working so that Deck can make a deck. Test this.
  3. Complete more of CardList so that Deck can shuffle the deck (only one version of exchange is needed). Test this.
  4. Complete the rest of CardList.
  5. Test CardList thoroughly.
  6. Implement the Dealer. Do not implement the Customer yet, as you will find that the two have much in common. It will be faster to get Dealer working fully, and then copy Dealer into Customer and modify Customer as needed.
  7. Rig the Customer so that no cards are drawn, and then run the program so the Dealer plays. Verify that the Dealer behaves correctly.
  8. Copy and paste all code (except wantsCard) from the Dealer into the Customer.
  9. Complete your testing.

Last modified 08:00:12 CST 03 March 1999 by Ron K. Cytron