|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object smithers.cards.Card
public class Card
Class to store a playing card from a standard 52-card poker or bridge deck. A card consists of a rank (Ace, 2-10, Jack, Queen or King) and a suit (Clubs, Diamonds, Hearts or Spades). Instances of this class are immutable.
Field Summary | |
---|---|
static char[] |
RANKS
|
static char[] |
SUITS
|
Constructor Summary | |
---|---|
Card()
Constructs the Ace of Clubs. |
|
Card(char rank,
char suit)
Creates a card with given rank and suit both specified as char. |
|
Card(int index)
Creates a card from a single integer in the range 0-51. |
|
Card(int rank,
char suit)
Creates a card with given rank and suit. |
|
Card(int rank,
int suit)
Creates a card with given rank and suit both specified as int. |
Method Summary | |
---|---|
int |
compareRank(Card card)
Finds the signed difference between the ranks of 2 cards. |
boolean |
equals(java.lang.Object o)
Checks if another card is the same as this one. |
char |
getColor()
Gets the colour of this card. |
char |
getColour()
Gets the colour of this card. |
int |
getRank()
Gets the rank of this card. |
char |
getRankAsChar()
Gets the rank of this card as a char. |
int |
getRankAsInt()
Gets the rank of this card as an int. |
java.lang.String |
getRankAsString()
Gets the rank of this card as a String. |
char |
getSuit()
Gets the suit of this card. |
char |
getSuitAsChar()
Gets the suit of this card as a char. |
int |
getSuitAsInt()
Gets the suit of this card as an int. |
java.lang.String |
getSuitAsString()
Gets the suit of this card as a String. |
boolean |
sameColor(Card card)
Checks if another Card is the same colour as this one. |
boolean |
sameColour(Card card)
Checks if another Card is the same colour as this one. |
boolean |
sameRank(Card card)
Checks if another Card has the same rank as this one. |
boolean |
sameSuit(Card card)
Checks if another Card has the same suit as this one. |
int |
toInt()
Produces an integer representation of the card based on suit then rank. |
int |
toInt(boolean aceHigh)
Produces an integer representation of the card based on suit then rank. |
java.lang.String |
toString()
Produces a 2 character String representing this card. |
java.lang.String |
toStringFull()
Produces a String representation of this card. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final char[] SUITS
public static final char[] RANKS
Constructor Detail |
---|
public Card()
public Card(int rank, char suit)
rank
- the rank of the card (1=A, 11=J, 12=Q, 13=K)suit
- the suit of the card (C, D, H, S)public Card(int rank, int suit)
rank
- the rank of the card (1=A, 11=J, 12=Q, 13=K)suit
- the suit of the card (0=C, 1=D, 2=H, 3=S)public Card(char rank, char suit)
rank
- the rank of the card (A, 2-9, T, J, Q, K)suit
- the suit of the card (C, D, H, S)public Card(int index)
index
- a the index of the card from 0-51Method Detail |
---|
public int getRank()
int
public char getRankAsChar()
char
public int getRankAsInt()
int
public java.lang.String getRankAsString()
String
representing the rankpublic char getSuit()
char
public char getSuitAsChar()
char
public int getSuitAsInt()
int
public java.lang.String getSuitAsString()
String
representing the suitpublic char getColour()
'B'
or 'R'
depending on the suitpublic char getColor()
'B'
or 'R'
depending on the suitgetColour()
public java.lang.String toString()
toString
in class java.lang.Object
String
represention of this cardpublic java.lang.String toStringFull()
String
represention of this cardpublic int toInt()
toInt(boolean)
public int toInt(boolean aceHigh)
aceHigh
- true
if aces should be ranked high
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the Object
to test against
true
if o
is a Card
and represents the
same card as this onepublic boolean sameRank(Card card)
card
- the Card
to test against
true
if the cards have the same rankpublic boolean sameSuit(Card card)
card
- the Card
to test against
true
if the cards have the same suitpublic boolean sameColour(Card card)
card
- the Card
to test against
true
if the cards are the same colourpublic boolean sameColor(Card card)
card
- the Card
to test against
true
if the cards are the same coloursameColour(smithers.cards.Card)
public int compareRank(Card card)
card
- Card
to test against
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |