(Mondays 2 PM)
(Fridays 2 PM)
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.
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!
DirectionVectorare from Lab 2 . Use of
HandVizis 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
represents a playing card. Conceptually, a playing card has a
idis in the inclusive range 0...51. Let us assume that
Card c1 = new Card(15);creates a card with
id15, which represents the 3 of Diamonds.
Card class, we will need the following methods.
int getId()to return the id (0...51) of a card.
Cardshould be defined in terms of the card's suit and rank, though you might include the card's internal
Cardfor testing the class. Actually, this is provided for you. The method constructs each of the possible 52 cards and prints out the card using its
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):
Card getFirst()that returns the list's first
CardList getRest()that returns the rest of the list's cards.
boolean isShown()that tells if the list element's card (same card as
getFirst()) should be shown or not.
void setShown()that makes all cards in the list shown.
cardinality(pardon the pun) that takes no parameters and returns the number of cards in the list.
duplicatethat takes no parameters and returns a new
CardListthat begins a list with the same
Cards but not the same
CardListreferences (this will be explained in class).
reversethat takes no parameters and returns a new linked-list that contains this list's cards but in the reverse order.
pointsthat can be iterative or recursive (your choice). This method takes no parameters and computes the point total for the list.
CardList findCard(Card)that returns the first
CardListthat contains the specified
Card. If none can be found, then null is returned.
CardList findCard(int i)that returns the ith element in the list, if the list as enough elements to do that; otherwise, null is returned
Cardwith the specified
Card, if the specified
Cardis in the list.
exchange(CardList)that swaps this
Cardwith the specified
This class is provided to you for this lab. However, it won't work
properly until your
are implemented. This class has the following methods.
Each of these classes must provide the following methods
boolean wantsCard()returns true if another card is desired.
void takeCard(Card, boolean)accepts a new card into the player's hand. The
booleanparameter specifies if the card should be shown.
void takeCard(Card)is the same as above, but the card is definitely shown. See how cards are dealt in
Startup.javato see how these constructors are used.
boolean busted()returns true if the player's hand contains over 21 points.
CardListare given. For your design, do the following.
CardList, provide code for the
Customerclass (as given) decides whether to want more cards or not.
Dealer. Your testing must include coverage of all methods in
CardListworking so that
Deckcan make a deck. Test this.
Deckcan shuffle the deck (only one version of
exchangeis needed). Test this.
Dealer. Do not implement the
Customeryet, as you will find that the two have much in common. It will be faster to get
Dealerworking fully, and then copy
Customerso that no cards are drawn, and then run the program so the
Dealerplays. Verify that the
wantsCard) from the