| Lab | Assigned | Design Due (Mondays 2 PM) |
Lab Due (Fridays 2 PM) |
|||
|---|---|---|---|---|---|---|
| 19 | Feb | 8 | Mar | 19 | Mar | |
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!
Lab6.java
Startup.java
Card.java
CardList.java
Deck.java
Dealer.java
Customer.java
MousePad.java
DirectionVector.java
HandViz.java
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.*;
Card.java
Design and implement the class Card.java that
represents a playing card. Conceptually, a playing card has a
id, where
id is in the inclusive range 0...51. Let us assume that
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.
int getId() to return the id (0...51) of a card.
toString() of a Card should be defined
in terms of the card's suit and rank, though you might include the card's
internal id.
Card for 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 toString().
CardList.java
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
Card.
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.
duplicate that takes no
parameters and returns a new CardList that begins a list
with the same Cards but not the same CardList
references (this will be explained in class).
reverse that takes no
parameters and returns a new
linked-list that contains this list's cards but in the reverse order.
points that 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
CardList that 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
exchange(Card) swaps this
CardList's Card with the specified Card,
if the specified Card is in the list.
exchange(CardList) that swaps
this
CardList's Card with the specified
CardList's Card.
Deck.java
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.
Deck()
void shuffle()
Card draw()
Customer and Dealer
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 boolean parameter 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.java to see how
these constructors are used.
boolean busted() returns true if the player's
hand contains over 21 points.
Card class.
CardList are given. For
your design, do the following.
CardList.
CardList.
CardList,
provide code for the Dealer's wantCard method,
assuming
Customer class
(as given) decides whether to want more cards or not.
CardList and Dealer.
Your testing must include coverage
of all methods in CardList.
Card working.
CardList working so that
Deck can make a deck. Test this.
CardList so that Deck
can shuffle the deck (only one version of exchange is needed).
Test this.
CardList.
CardList thoroughly.
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.
Customer so that no cards are drawn, and then run
the program so the Dealer plays. Verify that the Dealer behaves correctly.
wantsCard)
from the Dealer into the Customer.