Class Deck

java.lang.Object
  extended byDeck
Direct Known Subclasses:
ZetDeck

public class Deck
extends java.lang.Object


Constructor Summary
Deck()
          Constructs an empty deck of cards.
Deck(int capacity)
          Constructs an empty deck of cards with a given capacity.
 
Method Summary
 void add(Card card)
          Adds a given card at the top of this deck.
 int getNumCards()
          Returns the number of cards in this deck.
 boolean isEmpty()
          Indicates whether this deck is empty.
 void shuffle()
          Shuffles this deck.
 void sort()
          Sorts this deck in acsending order of IDs.
 Card takeTop()
          Removes and returns the top card from this deck.
 java.lang.String toString()
          Returns a string representation of this deck.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Deck

public Deck()
Constructs an empty deck of cards.


Deck

public Deck(int capacity)
Constructs an empty deck of cards with a given capacity.

Parameters:
capacity - the number of cards this deck can hold without expanding the ArrayList that holds the cards.
Method Detail

getNumCards

public int getNumCards()
Returns the number of cards in this deck.

Returns:
the number of cards in this deck.

isEmpty

public boolean isEmpty()
Indicates whether this deck is empty.

Returns:
true if the deck is empty; false otherwise.

add

public void add(Card card)
Adds a given card at the top of this deck.

Parameters:
card - to be added.

takeTop

public Card takeTop()
Removes and returns the top card from this deck.

Returns:
the top card.
Throws:
java.util.NoSuchElementException - if this deck is empty.

shuffle

public void shuffle()
Shuffles this deck.


sort

public void sort()
Sorts this deck in acsending order of IDs.


toString

public java.lang.String toString()
Returns a string representation of this deck.

Returns:
a String representation of this deck.