| Lab | Assigned | Design Due (In class) 10 AM |
Implement (In Lab) |
Demo (In Lab) |
Lab Due (In class) Friday 10 AM |
|||||
|---|---|---|---|---|---|---|---|---|---|---|
| 28 | Oct | None | 29-30 | Oct | 5-6 | Nov | 8 | Nov | ||
(extends).
Startup.java file you had from
last lab with the one below:
This lab is the second of a multiweek sequence that will culminate in the creation of a working card game.
You have
implemented a StackOfCards, which we will now use to
implement a Deck.
Deck is-a StackOfCards, but
with some extra functionality. So this will be our first time for
creating one class by extenidng another:
Deck
extends StackOfCards in this lab.
You will need to create your own .java files for the classes that we have not provided. You will probably also need to make your own Startup.java to test your code, but you will not need to turn that file in. All grading will be done with the provided Startup.java file.
All methods below are public. You may not add other public methods. All methods you add must be private. You are encouraged to add private methods where you see fit.
**See the JavaDoc for the same information presented differently**
Deck class,
which you must complete according to the API below. The Deck is an abstract data type, so as with StackOfCards, it can be implemented in many ways. Our implementation of the Deck will extend StackOfCards.Deck must have the following methods:Deck()
int getSize()
Card getTop()
Card peek() in StackOfCards.
Card getBottom()
Card getNthFromTop(int n)
int getSize() must be updated in this case.
void push(Card c)
push method in StackOfCards. The Deck
keeps track of the number of cards it contains, while StackOfCards
does not. This method should appropriately adjust the value
to be returned by getSize(), as well as performing
the push() from StackOfCards.
Card pop()
pop method in StackOfCards. Look at
void push(Card c) for more detail on method function.
Card removeTop()
Card pop()
Card removeBottom()
Card removeNthFromTop(int n)
void perfectShuffle()
void selectionShuffle()
Card peek(), boolean
isEmpty(), String toString.
As with Card, for grading purposes, we will constrain your implementation of the Deck.
When the deck is constructed, the cards in it must be in the following order, from the top of the stack down:
Ace of Spades, Ace of Hearts, Ace of Diamonds, Ace of Clubs, King of Spades, Hearts, Diamonds, Clubs, etc. The bottom
4 cards should be Two of Spades, Two of Hearts, Two of Diamonds, Two of Clubs.
Hand. It is the hand of cards that is actually used to
play the game, and not user as a source of cards (like the Deck is).
Our Hand class has-a ListOfCards
that keeps track of all the Card objects currently in the hand.
Here's the API for Hand:
Hand()
Hand with an empty DrawingPane
and ListOfCards. Cards in the hand are invisible (face down) by default.
DrawingPane getDrawingPane()
DrawingPane on which the Hand
draws itself.
int getSize()
boolean isEmpty()
boolean isVisible()
Card getCard(int n)
void add(Card c)
Card to the Hand.
This constitutes adding both to the ListOfCards and to the
Hand's DrawingPane. More recently added cards go to the end of the hand.
void remove(Card c)
Card remove(int n)
void setVisible(boolean visible)
Card's visibility to the specified visibility.
void clear()
DrawingPane and empties
its ListOfCards.
void sort()
Hand by rank (i.e. from high to low, with Aces high).
Changes in order are reflected both visually and internally.
This method is worth 5 lab points of extra credit. It is tested from Startup, so you must include at least a stub for this method if not the actual implementation.
String toString()
Startup
class to demonstrate that your classes work. To ease grading, this class is provided
for you. Ideally, the transcript generated by the reference implementation
and your code will be identical. You should not, however, rely solely on our Startup code
entirely during your own testing. After, for example, you finish the Card class,
you should make completely sure that it works as expected before moving on.
Startup()
Startup object which tests the other classes in this lab.
Read the following carefully, and be sure to complete all parts below.
Deck and Hand generated by the given Startup.java
Deck.
Hand
Good Luck!