public class CardStack
extends java.lang.Object
Constructor and Description |
---|
CardStack() |
Modifier and Type | Method and Description |
---|---|
void |
addCard(Card card)
Add the given card to the top of the stack.
|
boolean |
canPlayFrom()
Returns true if a card may be removed from this stack and otherwise throws an IllegalPlayException ("You cannot play from an empty stack.").
|
Card |
getTopCard()
Return the top card or throw an EmptyStackException if empty.
|
boolean |
isEmpty()
Return whether or not the card stack is empty.
|
boolean |
playTo(Card card)
Given a card to be played to the top of this card stack, either make the legal play and return true, or ignore the illegal play and throw an appropriate Exception.
|
boolean |
playTo(CardStack otherStack)
Given a stack from which the top card is to be played to the top of this card stack, either make the legal play and return true, or throw an appropriate IllegalPlayException.
|
Card |
removeTopCard()
Remove the top card and return it or throw an EmptyStackException if empty.
|
int |
size()
Return the size of the card stack.
|
Card[] |
toArray()
Return an array of Card objects in this stack, ordered bottom to top.
|
java.lang.String |
toString() |
protected java.util.Stack<Card> stack
public void addCard(Card card)
card
- card to addpublic boolean canPlayFrom() throws IllegalPlayException
IllegalPlayException
- "You cannot play from an empty stack." in the case of an empty stack.public Card getTopCard() throws java.util.EmptyStackException
java.util.EmptyStackException
public boolean isEmpty()
public boolean playTo(Card card) throws IllegalPlayException, java.lang.NullPointerException
card
- card to be played onto this card stackIllegalPlayException
- if an illegal play is attemptedjava.lang.NullPointerException
- if the given card parameter is nullpublic boolean playTo(CardStack otherStack) throws IllegalPlayException
otherStack
- the other stack from which the top card is to be playedIllegalPlayException
- thrown if an IllegalPlayException is thrown by a call to canPlayFrom() or playTo(CardStack) calls.public Card removeTopCard()
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public Card[] toArray()