Class Deck

java.lang.Object
  extended by Deck

public class Deck
extends java.lang.Object

This class models a deck of fifty-two ordinary playing cards OR a deck of fifty-four cards that includes two jokers.


Constructor Summary
Deck()
          Constructs a new deck of cards, ace through king of each suit, with the suits in "bridge-order."
Deck(int n)
          Constructs a new deck of n cards; the only Permissable values for n are 52 and 54.
 
Method Summary
 Card cardAt(int i)
          Returns (a copy of) the card at index i in this deck.
 boolean contains(Card c)
          Returns true iff this deck contains at least one card that is just like Card c.
static double dispersion(Deck d1, Deck d2)
          Returns the dispersion between two joker-less decks, defined as the average (absolute) distance that each card has to move in order to transform d1 into d2.
 boolean equals(Deck d)
          Returns true iff this deck and d are identically constructed.
 boolean isCrooked()
          Returns true iff this deck is crooked (contains multiple copies of some card or cards).
static void main(java.lang.String[] args)
          Skeleton suite of unit tests for the "missing" methods, above.
 void putCard(Card c, int i)
           
 void randomShuffle()
          Performs a randomized shuffle of this deck.
 void riffleShuffle()
          Performs a riffle shuffle of this deck, i.e., the kind of shuffle you do by hand.
 int size()
          Returns the size of the deck (52 for normal decks, 54 for decks with jokers).
 java.lang.String toString()
          Returns a representation of this deck.
 int whereIs(Card c)
          Returns the index of (the first example of) card c in this deck (-1 if not found).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Deck

public Deck()
Constructs a new deck of cards, ace through king of each suit, with the suits in "bridge-order."


Deck

public Deck(int n)
Constructs a new deck of n cards; the only Permissable values for n are 52 and 54. For n == 52, this works the same as the default constructor); for n == 54, this should construct a new deck with two jokers at the bottom of the deck).

Method Detail

dispersion

public static double dispersion(Deck d1,
                                Deck d2)
Returns the dispersion between two joker-less decks, defined as the average (absolute) distance that each card has to move in order to transform d1 into d2.


cardAt

public Card cardAt(int i)
Returns (a copy of) the card at index i in this deck. The top card is at index zero.


toString

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

Overrides:
toString in class java.lang.Object

size

public int size()
Returns the size of the deck (52 for normal decks, 54 for decks with jokers).


riffleShuffle

public void riffleShuffle()
Performs a riffle shuffle of this deck, i.e., the kind of shuffle you do by hand.


randomShuffle

public void randomShuffle()
Performs a randomized shuffle of this deck.


contains

public boolean contains(Card c)
Returns true iff this deck contains at least one card that is just like Card c.


putCard

public void putCard(Card c,
                    int i)

whereIs

public int whereIs(Card c)
Returns the index of (the first example of) card c in this deck (-1 if not found).


equals

public boolean equals(Deck d)
Returns true iff this deck and d are identically constructed.


isCrooked

public boolean isCrooked()
Returns true iff this deck is crooked (contains multiple copies of some card or cards).


main

public static void main(java.lang.String[] args)
Skeleton suite of unit tests for the "missing" methods, above.