Class Card
- java.lang.Object
-
- Card
-
public class Card extends java.lang.Object
An object of type Card represents a playing card from a standard Poker deck, including Jokers. The card has a suit, which can be spades, hearts, diamonds, clubs, or joker. A spade, heart, diamond, or club has one of the 13 values: ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, or king. Note that "ace" is considered to be the smallest value. A joker can also have an associated value; this value can be anything and can be used to keep track of several different jokers.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getSuit()
Returns the suit of this card.java.lang.String
getSuitAsString()
Returns a String representation of the card's suit.int
getValue()
Returns the value of this card.java.lang.String
getValueAsString()
Returns a String representation of the card's value.java.lang.String
toString()
Returns a string representation of this card, including both its suit and its value (except that for a Joker with value 1, the return value is just "Joker").
-
-
-
Field Detail
-
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
-
JOKER
public static final int JOKER
- See Also:
- Constant Field Values
-
ACE
public static final int ACE
- See Also:
- Constant Field Values
-
JACK
public static final int JACK
- 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
-
-
Constructor Detail
-
Card
public Card()
Creates a Joker, with 1 as the associated value. (Note that "new Card()" is equivalent to "new Card(1,Card.JOKER)".)
-
Card
public Card(int theValue, int theSuit)
Creates a card with a specified suit and value.- Parameters:
theValue
- the value of the new card. For a regular card (non-joker), the value must be in the range 1 through 13, with 1 representing an Ace. You can use the constants Card.ACE, Card.JACK, Card.QUEEN, and Card.KING. For a Joker, the value can be anything.theSuit
- the suit of the new card. This must be one of the values Card.SPADES, Card.HEARTS, Card.DIAMONDS, Card.CLUBS, or Card.JOKER.- Throws:
java.lang.IllegalArgumentException
- if the parameter values are not in the permissible ranges
-
-
Method Detail
-
getSuit
public int getSuit()
Returns the suit of this card.
-
getValue
public int getValue()
Returns the value of this card.- Returns:
- the value, which is one the numbers 1 through 13, inclusive for a regular card, and which can be any value for a Joker.
-
getSuitAsString
public java.lang.String getSuitAsString()
Returns a String representation of the card's suit.- Returns:
- one of the strings "Spades", "Hearts", "Diamonds", "Clubs" or "Joker".
-
getValueAsString
public java.lang.String getValueAsString()
Returns a String representation of the card's value.- Returns:
- for a regular card, one of the strings "Ace", "2", "3", ..., "10", "Jack", "Queen", or "King". For a Joker, the string is always a numerical.
-
toString
public java.lang.String toString()
Returns a string representation of this card, including both its suit and its value (except that for a Joker with value 1, the return value is just "Joker"). Sample return values are: "Queen of Hearts", "10 of Diamonds", "Ace of Spades", "Joker", "Joker #2"- Overrides:
toString
in classjava.lang.Object
-
-