Class Card

java.lang.Object
  extended by Card

public class Card
extends java.lang.Object

class Card here represents a playing card

Version:
27 Sept 2008
Author:
Chris Thiel

Field Summary
static int CLUBS
           
static int DIAMONDS
           
static int HEARTS
           
static java.lang.String[] pipName
          pipName is an array that contains the name of the card's pips so that the index matches the number of the card.
static int SPADES
           
static java.lang.String[] suitName
          suitName is an array contains the name of the Suit so that the index matches the suit number
static java.lang.String[] suitSymbol
          suitSymbol Have the unicode values to print the correct symbol, arranges so thet the index matches the suit number
 
Constructor Summary
Card()
          Default Constructor for objects of class Card is a random card of a random suit
Card(int p, int s)
          A Card can be constructed with a determined number of pips (and integer 1-13) and suit (an integer from 0-3)
Card(java.lang.String p, java.lang.String s)
          A Card can be constructed with a determined number of pips (a String "Ace" to "King") and suit (a String "Clubs" to "Spades")
 
Method Summary
 int comparePips(Card c)
          comparePips will return the difference between two cards' number of pips.
 int comparePipsAceHigh(Card c)
          comparePipsAceHigh will return the difference between two cards' number of pips, Ace High.
 boolean equals(Card c)
          Two cards are equal if they have the same number of pips.
 int getPips()
           
 int getSuit()
           
 int getValue()
           
 int indexOf(java.lang.String[] a, java.lang.String s)
          indexOf returns the index of the String s in the String Array a (it returns -1 if not found).
 java.lang.String info()
          info will return the contents of the card in a short two character string
 boolean isLessThan(Card c)
          isLessThan will compare two cards by pips, and in case of a match, will compare the suit.
 void setPips(int p)
          setPips changes the Card's pips,
 void setSuit(int s)
          setSuit changes the Card's suit,
 java.lang.String toString()
          toString will return the contents of the card in a string format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLUBS

public static final int CLUBS
See Also:
Constant Field Values

DIAMONDS

public static final int DIAMONDS
See Also:
Constant Field Values

HEARTS

public static final int HEARTS
See Also:
Constant Field Values

pipName

public static final java.lang.String[] pipName
pipName is an array that contains the name of the card's pips so that the index matches the number of the card. For example pipName[1] has a "Ace"


SPADES

public static final int SPADES
See Also:
Constant Field Values

suitName

public static final java.lang.String[] suitName
suitName is an array contains the name of the Suit so that the index matches the suit number


suitSymbol

public static final java.lang.String[] suitSymbol
suitSymbol Have the unicode values to print the correct symbol, arranges so thet the index matches the suit number

Constructor Detail

Card

public Card()
Default Constructor for objects of class Card is a random card of a random suit


Card

public Card(int p,
            int s)
A Card can be constructed with a determined number of pips (and integer 1-13) and suit (an integer from 0-3)


Card

public Card(java.lang.String p,
            java.lang.String s)
A Card can be constructed with a determined number of pips (a String "Ace" to "King") and suit (a String "Clubs" to "Spades")

Method Detail

comparePips

public int comparePips(Card c)
comparePips will return the difference between two cards' number of pips. The suit is ignored with this comparison. Here the ace is low. If the two cards happen to have the same number of pips, it returns the integer 0. If, for example, card1 is a 2 of clubs and card2 is a 6 of spades, then card1.comparePips(card2) returns -4, since card1 has four less pips than card2.

Returns:
the difference between number of pips

comparePipsAceHigh

public int comparePipsAceHigh(Card c)
comparePipsAceHigh will return the difference between two cards' number of pips, Ace High. The suit is ignored with this comparison, but the Ace is above a King. If the two cards happen to have the same number of pips, it returns the integer 0. If, for example, card1 is an ace of clubs and card2 is a queen of spades, then card1.comparePips(card2) returns 2, since card1 is two larger than card2.

Returns:
the difference between number of pips

equals

public boolean equals(Card c)
Two cards are equal if they have the same number of pips. The suit is ignored with this comparison

Returns:
true if they match the number of pips

getPips

public int getPips()
Returns:
getPips returns the Card's pips, an int from 1 to 13 where an Ace is a 1 and a King is a 13.

getSuit

public int getSuit()
Returns:
getSuit returns the Card's suit, an int from 0 to 3

getValue

public int getValue()
Returns:
getSuit returns the Card's suit, an int from 0 to 3

indexOf

public int indexOf(java.lang.String[] a,
                   java.lang.String s)
indexOf returns the index of the String s in the String Array a (it returns -1 if not found). This method ignores case.


info

public java.lang.String info()
info will return the contents of the card in a short two character string

Returns:
The pips and suit of a card

isLessThan

public boolean isLessThan(Card c)
isLessThan will compare two cards by pips, and in case of a match, will compare the suit. If the number of pips match, then the higher suit is considered. The the order of the suits (from high to low) is SPADES, HEARTS, DIAMONDS, CLUBS The Ace is low, and is considered to be below a 2. If the two cards happen to have the same number of pips, it then compares the suit returns the integer 0. If, for example, card1 is an ace of clubs and card2 is a 2 of spades, then card1.comparePips(card2) returns true, since card1 is less than card2. If card1 is a 6 of hearts and card2 is a 6 of clubs, than card1.isLessThan(card2) returns false, since hearts is greater than clubs

Returns:
the difference between number of pips

setPips

public void setPips(int p)
setPips changes the Card's pips,

Parameters:
the - pips are an integer from 1 to 13, where 1 is an Ace and 13 is a King.

setSuit

public void setSuit(int s)
setSuit changes the Card's suit,

Parameters:
the - suit 0 to 3. You can use the predefined integer constants SPADES, HEARTS, DIAMONDS and CLUBS from the Card class.

toString

public java.lang.String toString()
toString will return the contents of the card in a string format

Overrides:
toString in class java.lang.Object
Returns:
The pips and suit of a card