java.lang.Comparable<Card>public class Card extends java.lang.Object implements java.lang.Comparable<Card>
Deck| Modifier and Type | Field | Description |
|---|---|---|
static int |
ACE_INT |
the integer value assigned to the Ace rank
|
static java.lang.String |
ACE_STR |
the String value assigned to the Ace rank (internally)
|
static int |
CLUBS_INT |
the integer value assigned to the clubs suit
|
static java.lang.String |
CLUBS_STR |
the String value assigned to the clubs suit
|
static int |
DIAMONDS_INT |
the integer value assigned to the diamonds suit
|
static java.lang.String |
DIAMONDS_STR |
the String value assigned to the diamonds suit
|
static int |
EIGHT_INT |
the integer value assigned to the Eight rank
|
static java.lang.String |
EIGHT_STR |
the String value assigned to the Eight rank (internally)
|
static int |
ERROR_INT |
the integer value returned by some methods if there is an error
|
static java.lang.String |
ERROR_STR |
the String value returned by a method if there is an error
|
static int |
FIVE_INT |
the integer value assigned to the Five rank
|
static java.lang.String |
FIVE_STR |
the String value assigned to the Five rank (internally)
|
static int |
FOUR_INT |
the integer value assigned to the Four rank
|
static java.lang.String |
FOUR_STR |
the String value assigned to the Four rank (internally)
|
static int |
HEARTS_INT |
the integer value assigned to the hearts suit
|
static java.lang.String |
HEARTS_STR |
the String value assigned to the hearts suit
|
static int |
JACK_INT |
the integer value assigned to the Jack rank
|
static java.lang.String |
JACK_STR |
the String value assigned to the Jack rank (internally)
|
static int |
KING_INT |
the integer value assigned to the King rank
|
static java.lang.String |
KING_STR |
the String value assigned to the King rank (internally)
|
static int |
NINE_INT |
the integer value assigned to the Nine rank
|
static java.lang.String |
NINE_STR |
the String value assigned to the Nine rank (internally)
|
static int |
QUEEN_INT |
the integer value assigned to the Queen rank
|
static java.lang.String |
QUEEN_STR |
the String value assigned to the Queen rank (internally)
|
private int |
rank |
the rank value of the Card;
assignments of ranks that don't directly match to a number:
1 = ace, 11 = jack, 12 = queen, 13 = king
|
static int |
SEVEN_INT |
the integer value assigned to the Seven rank
|
static java.lang.String |
SEVEN_STR |
the String value assigned to the Seven rank (internally)
|
static int |
SIX_INT |
the integer value assigned to the Six rank
|
static java.lang.String |
SIX_STR |
the String value assigned to the Six rank (internally)
|
static int |
SPADES_INT |
the integer value assigned to the spades suit
|
static java.lang.String |
SPADES_STR |
the String value assigned to the spades suit
|
private java.lang.String |
suit |
the suit value of the Card;
could be: "Clubs", "Hearts", "Diamonds", or "Spades"
|
static int |
TEN_INT |
the integer value assigned to the Ten rank
|
static java.lang.String |
TEN_STR |
the String value assigned to the Ten rank (internally)
|
static int |
THREE_INT |
the integer value assigned to the Three rank
|
static java.lang.String |
THREE_STR |
the String value assigned to the Three rank (internally)
|
static int |
TWO_INT |
the integer value assigned to the Two rank
|
static java.lang.String |
TWO_STR |
the String value assigned to the Two rank (internally)
|
| Constructor | Description |
|---|---|
Card() |
Constructs a default card (the Ace of Clubs)
|
Card(int s,
int r) |
Constructs a Card using two integers
|
Card(int s,
java.lang.String r) |
Constructs a Card using a integer, for suit, and String, for rank.
|
Card(java.lang.String s,
int r) |
Constructs a Card using a String, for suit, and integer, for rank.
|
Card(java.lang.String s,
java.lang.String r) |
Constructs a Card using two Strings
|
| Modifier and Type | Method | Description |
|---|---|---|
int |
compareTo(Card other) |
Compares two Card objects using both suit and rank
|
boolean |
equals(java.lang.Object other) |
Checks if two Cards are equal
|
int |
getRank() |
Returns the rank of the card (as an integer)
|
private static int |
getRankInt(java.lang.String r) |
Returns the integer value of a given String rank.
|
java.lang.String |
getRankStr() |
Returns the rank (as a String)
|
java.lang.String |
getSuit() |
Returns the suit of a Card (as a String)
|
int |
getSuitInt() |
Returns the suit (as an int)
|
private static java.lang.String |
getSuitStr(int s) |
Returns the String value of a suit given as an integer.
|
java.lang.String |
toString() |
Returns a String object representing the Card's value e.g.
|
private java.lang.String suit
private int rank
public static final int CLUBS_INT
public static final int DIAMONDS_INT
public static final int HEARTS_INT
public static final int SPADES_INT
public static final java.lang.String CLUBS_STR
public static final java.lang.String DIAMONDS_STR
public static final java.lang.String HEARTS_STR
public static final java.lang.String SPADES_STR
public static final int ACE_INT
public static final int TWO_INT
public static final int THREE_INT
public static final int FOUR_INT
public static final int FIVE_INT
public static final int SIX_INT
public static final int SEVEN_INT
public static final int EIGHT_INT
public static final int NINE_INT
public static final int TEN_INT
public static final int JACK_INT
public static final int QUEEN_INT
public static final int KING_INT
public static final java.lang.String ACE_STR
public static final java.lang.String TWO_STR
public static final java.lang.String THREE_STR
public static final java.lang.String FOUR_STR
public static final java.lang.String FIVE_STR
public static final java.lang.String SIX_STR
public static final java.lang.String SEVEN_STR
public static final java.lang.String EIGHT_STR
public static final java.lang.String NINE_STR
public static final java.lang.String TEN_STR
public static final java.lang.String JACK_STR
public static final java.lang.String QUEEN_STR
public static final java.lang.String KING_STR
public static final java.lang.String ERROR_STR
public static final int ERROR_INT
public Card()
public Card(int s,
int r)
s - the value of suit in integer formr - the value of rank in integer formjava.lang.IllegalArgumentException - if rank or suit values are invalidpublic Card(java.lang.String s,
java.lang.String r)
s - the value of suit in String formr - the value of rank in String formjava.lang.IllegalArgumentException - if rank or suit values are invalidpublic Card(java.lang.String s,
int r)
s - the value of suit in String formr - the value of rank in int formjava.lang.IllegalArgumentException - if rank or suit values are invalidpublic Card(int s,
java.lang.String r)
s - the value of suit in int formr - the value of rank in String formjava.lang.IllegalArgumentException - if rank or suit values are invalidpublic java.lang.String getSuit()
public int getRank()
public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()public java.lang.String getRankStr()
public int getSuitInt()
public int compareTo(Card other)
compareTo in interface java.lang.Comparable<Card>other - the Card that this Card is being compared to.Comparable.compareTo(java.lang.Object)public boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - the Card that this Card is being checked for equality withprivate static java.lang.String getSuitStr(int s)
throws java.lang.IllegalArgumentException
s - the integer version of suit that will be used to find the String equivalentjava.lang.IllegalArgumentException - if the int given doesn't have a String equivalent for suitprivate static int getRankInt(java.lang.String r)
throws java.lang.IllegalArgumentException
r - the String value of the rank that it gets the int forjava.lang.IllegalArgumentException - if String r doesn't have an equivalent integer rank