game.model
Class Card

java.lang.Object
  extended by game.model.Card

public class Card
extends java.lang.Object

The Card class is used to represent cards in the deck. The cards have a suit and a rank and are initialized as such

Author:
jdavidso

Field Summary
static int ACE
           
static int CLUBS
           
static int DIAMONDS
           
static int HEARTS
           
static int JACK
           
static int KING
           
static int QUEEN
           
private  java.lang.Integer rank
           
static int SPADES
           
private  java.lang.String suit
           
 
Constructor Summary
Card()
          A default constructor with rank 0 and unsuited.
Card(int both)
           
Card(java.lang.Integer suit, java.lang.Integer rank)
          Constructor with an int representation of the suit
Card(java.lang.String cardString)
          This constructor constructs a card out of just a string.
Card(java.lang.String suit, java.lang.Integer rank)
          This is the constructor most often used to create a card with a given suit and rank.
 
Method Summary
 java.lang.Integer getRank()
          Returns the rank of the Card
 java.lang.String getSuit()
          Returns the suit of the Card
 int getSuitAsInt()
          Returns the suit of the Card as int
private  java.lang.String printRank()
          Returns a human readable rank from the rank integer.
private  java.lang.String printSuit()
          Returns the first character of the suit in lower case.
 int toInt()
          Returns an human easy recognizible int representation of the card.
 java.lang.String toString()
          Returns a human readable String representation of the Card given by the rank then the first character of the suit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rank

private java.lang.Integer rank

suit

private java.lang.String suit

DIAMONDS

public static final int DIAMONDS
See Also:
Constant Field Values

HEARTS

public static final int HEARTS
See Also:
Constant Field Values

SPADES

public static final int SPADES
See Also:
Constant Field Values

CLUBS

public static final int CLUBS
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

ACE

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

Card

public Card()
A default constructor with rank 0 and unsuited.


Card

public Card(java.lang.String suit,
            java.lang.Integer rank)
This is the constructor most often used to create a card with a given suit and rank.

Parameters:
suit - The String representation of a playing card suit
rank - The Integer representation of the card rank.

Card

public Card(java.lang.Integer suit,
            java.lang.Integer rank)
Constructor with an int representation of the suit

Parameters:
suit - The Integer representation of a playing card suit
rank - The Integer representation of the card rank.

Card

public Card(java.lang.String cardString)
This constructor constructs a card out of just a string. Strings are Rank then Suit, as such As for the Ace of spades, Kh for the king of hearts Qd for the queen of diamonds Jc for the Jack of clubs then Th for the 10 of hearts 9-2 for the other ranks

Parameters:
cardString - A String representation of the card

Card

public Card(int both)
Method Detail

getRank

public java.lang.Integer getRank()
Returns the rank of the Card

Returns:
rank

getSuit

public java.lang.String getSuit()
Returns the suit of the Card

Returns:
suit

getSuitAsInt

public int getSuitAsInt()
Returns the suit of the Card as int

Returns:
0: diamonds
1: hearts
2: spades
3: clubs

toString

public java.lang.String toString()
Returns a human readable String representation of the Card given by the rank then the first character of the suit. ie: 7d, Ac

Overrides:
toString in class java.lang.Object
Returns:
a String representing the card (Suit and Rank)

toInt

public int toInt()
Returns an human easy recognizible int representation of the card.
Example:
'suit: +20, val: +val // Ac: 3x20+14=74 // 2d: 0x20+2=2';

Returns:
getSuitAsInt() * 20 + getRank()

printSuit

private java.lang.String printSuit()
Returns the first character of the suit in lower case.

Returns:
substring(0,1) suit

printRank

private java.lang.String printRank()
Returns a human readable rank from the rank integer.

Returns:
rank {(0-9, T, J, Q, K, A }