Class Card

java.lang.Object
  extended by Card

public class Card
extends java.lang.Object

This class models a single, ordinary playing card, which possesses a rank and a suit or else is a "suitless" joker.


Field Summary
static int ACE
           
static int CLUBS
           
static int DEUCE
           
static int DIAMONDS
           
static int EIGHT
           
static int FIVE
           
static int FOUR
           
static int HEARTS
           
static int JACK
           
static int JOKER
           
static int KING
           
static int KNAVE
           
static int NINE
           
static int NO_SUIT
           
static int QUEEN
           
static int SEVEN
           
static int SIX
           
static int SPADES
           
static int TEN
           
static int THREE
           
static int TREY
           
static int TWO
           
 
Constructor Summary
Card(int r)
          Constructs a joker.
Card(int r, int s)
          Constructs a card with rank r and suit s (guaranteed not to be a joker).
 
Method Summary
 int compareTo(Card c)
          Returns the distance between this card and c in a new, joker-less deck.
 boolean equals(java.lang.Object c)
          Returns true iff this card is equivalent to c, with jokers allowed.
 boolean isJoker()
          Returns true iff this card is a joker.
 int rank()
          Returns this card's rank.
 java.lang.String rankName()
          Returns a string representing this card's rank.
 int suit()
          Returns this card's suit (or Card.NO_SUIT in the event of a joker).
 java.lang.String suitName()
          Returns a string representing this card's suit (or empty string in the event of Card.NO_SUIT).
 java.lang.String toString()
          Returns a string representing this card's name.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JOKER

public static final int JOKER
See Also:
Constant Field Values

ACE

public static final int ACE
See Also:
Constant Field Values

TWO

public static final int TWO
See Also:
Constant Field Values

DEUCE

public static final int DEUCE
See Also:
Constant Field Values

THREE

public static final int THREE
See Also:
Constant Field Values

TREY

public static final int TREY
See Also:
Constant Field Values

FOUR

public static final int FOUR
See Also:
Constant Field Values

FIVE

public static final int FIVE
See Also:
Constant Field Values

SIX

public static final int SIX
See Also:
Constant Field Values

SEVEN

public static final int SEVEN
See Also:
Constant Field Values

EIGHT

public static final int EIGHT
See Also:
Constant Field Values

NINE

public static final int NINE
See Also:
Constant Field Values

TEN

public static final int TEN
See Also:
Constant Field Values

JACK

public static final int JACK
See Also:
Constant Field Values

KNAVE

public static final int KNAVE
See Also:
Constant Field Values

QUEEN

public static final int QUEEN
See Also:
Constant Field Values

KING

public static final int KING
See Also:
Constant Field Values

NO_SUIT

public static final int NO_SUIT
See Also:
Constant Field Values

SPADES

public static final int SPADES
See Also:
Constant Field Values

HEARTS

public static final int HEARTS
See Also:
Constant Field Values

DIAMONDS

public static final int DIAMONDS
See Also:
Constant Field Values

CLUBS

public static final int CLUBS
See Also:
Constant Field Values
Constructor Detail

Card

public Card(int r,
            int s)
Constructs a card with rank r and suit s (guaranteed not to be a joker).


Card

public Card(int r)
Constructs a joker. The argument must be (equivalent to) Card.JOKER.

Method Detail

suit

public int suit()
Returns this card's suit (or Card.NO_SUIT in the event of a joker).


rank

public int rank()
Returns this card's rank.


rankName

public java.lang.String rankName()
Returns a string representing this card's rank.


suitName

public java.lang.String suitName()
Returns a string representing this card's suit (or empty string in the event of Card.NO_SUIT).


toString

public java.lang.String toString()
Returns a string representing this card's name.

Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(Card c)
Returns the distance between this card and c in a new, joker-less deck. If either card, or even both cards, are jokers, an UnsupportedOperationException is thrown.


isJoker

public boolean isJoker()
Returns true iff this card is a joker.


equals

public boolean equals(java.lang.Object c)
Returns true iff this card is equivalent to c, with jokers allowed.

Overrides:
equals in class java.lang.Object