cardgame
Class PlayingCard

java.lang.Object
  |
  +--cardgame.PlayingCard
All Implemented Interfaces:
Card

public class PlayingCard
extends java.lang.Object
implements Card

The PlayingCard class implements a basic card via the Card interface that can be used for various kinds of games. It represents the name, suit, value, front/back images, and visibility of a card, with get and set methods for each.

Version:
1.0, 15 July 2001
Author:
James A. Webb, www.uberkode.com

Field Summary
private  java.lang.String backImageFileName
          The private variable backImageFileName stores the file name that represents the back of a PlayingCard.
private  java.lang.String frontImageFileName
          The private variable frontImageFileName stores the file name that represents the front of a PlayingCard.
private  java.lang.String name
          The private variable name represents the common name of a PlayingCard, such as "Ace," "Deuce," or "King."
private  java.lang.String suit
          The private variable suit represents one of the four standard suits, such as "Heart," "Spade," "Diamond," or "Club."
private  int value
          The private variable value represents the numerical value of a PlayingCard.
private  boolean visibility
          The private variable visibility indicates whether a PlayingCard is face up (true) or face down (false).
 
Fields inherited from interface cardgame.Card
ACE, CLUB, DIAMOND, EIGHT, FIVE, FOUR, HEART, JACK, KING, NINE, QUEEN, SEVEN, SIX, SPADE, TEN, THREE, TWO
 
Constructor Summary
PlayingCard()
          The no-argument constructor sets the PlayingCard's variables to default values.
PlayingCard(java.lang.String cardName, java.lang.String cardSuit)
          This basic constructor sets the PlayingCard's name and suit.
PlayingCard(java.lang.String cardName, java.lang.String cardSuit, int cardValue)
          This constructor sets the PlayingCard's name, suit, and value parameters.
PlayingCard(java.lang.String cardName, java.lang.String cardSuit, int cardValue, java.lang.String cardFront, java.lang.String cardBack)
          This constructor sets the PlayingCard's name, suit, front, and back images.
 
Method Summary
 boolean equals(Card theOtherPlayingCard)
          The public method equals checks whether two PlayingCards have the same name and suit, and returns a boolean result.
 java.lang.String getBackImageFileName()
          The public method getBackImageFileName returns the file name containing a PlayingCard's back image.
 java.lang.String getFrontImageFileName()
          The public method getFrontImageFileName returns the file name containing a PlayingCard's front image.
 java.lang.String getName()
          The public method getName returns the name of a PlayingCard.
 java.lang.String getSuit()
          The public method getSuit returns the suit of a Card.
 int getValue()
          The public method getValue returns the numeric value of a PlayingCard.
 boolean getVisibility()
          The public method getVisibility is used to retrieve the current state of a PlayingCard's visibility.
 void setBackImageFileName(java.lang.String backImageFile)
          The public method setBackImageFileName specifies the file name containing a PlayingCard's back image.
 void setFrontImageFileName(java.lang.String frontImageFile)
          The public method setFrontImageFileName specifies the file name containing a PlayingCard's front image.
 void setName(java.lang.String cardName)
          The public method setName sets the name of a PlayingCard.
 void setSuit(java.lang.String cardSuit)
          The public method setSuit sets the suit of a PlayingCard.
 void setValue(int cardValue)
          The public method setValue sets the numeric value of a PlayingCard.
 void setVisibility(boolean visible)
          The public method setVisibility is used to set a PlayingCard's current state of visibility.
 java.lang.String toString()
          The public method toString returns the String representation of a PlayingCard, such as "Ace of Spades."
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

name

private java.lang.String name
The private variable name represents the common name of a PlayingCard, such as "Ace," "Deuce," or "King."
See Also:
getName(), setName(String cardName)

suit

private java.lang.String suit
The private variable suit represents one of the four standard suits, such as "Heart," "Spade," "Diamond," or "Club."
See Also:
getSuit(), setSuit(String cardSuit)

value

private int value
The private variable value represents the numerical value of a PlayingCard. Its value only has meaning for a particular type of card game.
See Also:
getValue(), setValue(int cardValue)

frontImageFileName

private java.lang.String frontImageFileName
The private variable frontImageFileName stores the file name that represents the front of a PlayingCard. Normally, the front image is unique for all cards in a deck, and displays the card's name and suit.
See Also:
getFrontImageFileName(), setFrontImageFileName(String frontImageFile)

backImageFileName

private java.lang.String backImageFileName
The private variable backImageFileName stores the file name that represents the back of a PlayingCard. Normally, the same back image will be used for all cards in a deck.
See Also:
getBackImageFileName(), setBackImageFileName(String backImageFile)

visibility

private boolean visibility
The private variable visibility indicates whether a PlayingCard is face up (true) or face down (false). The default is false.
See Also:
getVisibility(), setVisibility(boolean visible)
Constructor Detail

PlayingCard

public PlayingCard()
The no-argument constructor sets the PlayingCard's variables to default values.

PlayingCard

public PlayingCard(java.lang.String cardName,
                   java.lang.String cardSuit)
This basic constructor sets the PlayingCard's name and suit.
Parameters:
cardName - the name of the PlayingCard as a String.
cardSuit - the suit of the PlayingCard as a String.

PlayingCard

public PlayingCard(java.lang.String cardName,
                   java.lang.String cardSuit,
                   int cardValue)
This constructor sets the PlayingCard's name, suit, and value parameters.
Parameters:
cardName - the name of the PlayingCard as a String.
cardSuit - the suit of the PlayingCard as a String.
cardValue - the value of the PlayingCard as an int.

PlayingCard

public PlayingCard(java.lang.String cardName,
                   java.lang.String cardSuit,
                   int cardValue,
                   java.lang.String cardFront,
                   java.lang.String cardBack)
This constructor sets the PlayingCard's name, suit, front, and back images. The image parameters are the filenames in .gif or .jpg format.
Parameters:
cardName - the name of the PlayingCard as a String.
cardSuit - the suit of the PlayingCard as a String.
cardValue - the value of the PlayingCard as an int.
cardFront - the name of the front image file as a String, such as "aceofspades.jpg".
cardBack - the name of the back image file as a String, such as "bicycle.jpg".
Method Detail

getName

public java.lang.String getName()
The public method getName returns the name of a PlayingCard.
Specified by:
getName in interface Card
Returns:
the name of a PlayingCard as a String.

setName

public void setName(java.lang.String cardName)
The public method setName sets the name of a PlayingCard.
Specified by:
setName in interface Card
Parameters:
cardName - the name of a PlayingCard as a String.

getSuit

public java.lang.String getSuit()
The public method getSuit returns the suit of a Card.
Specified by:
getSuit in interface Card
Returns:
the suit of a PlayingCard as a String.

setSuit

public void setSuit(java.lang.String cardSuit)
The public method setSuit sets the suit of a PlayingCard.
Specified by:
setSuit in interface Card
Parameters:
cardSuit - the suit of a PlayingCard as a String.

getValue

public int getValue()
The public method getValue returns the numeric value of a PlayingCard.
Specified by:
getValue in interface Card
Returns:
the value of a PlayingCard as an int.

setValue

public void setValue(int cardValue)
The public method setValue sets the numeric value of a PlayingCard.
Specified by:
setValue in interface Card
Parameters:
cardValue - the numeric value of a PlayingCard as an int.

getFrontImageFileName

public java.lang.String getFrontImageFileName()
The public method getFrontImageFileName returns the file name containing a PlayingCard's front image.
Specified by:
getFrontImageFileName in interface Card
Returns:
the String value of the front image file name.

setFrontImageFileName

public void setFrontImageFileName(java.lang.String frontImageFile)
The public method setFrontImageFileName specifies the file name containing a PlayingCard's front image.
Specified by:
setFrontImageFileName in interface Card
Parameters:
frontImageFile - the String value of the front image file name.

getBackImageFileName

public java.lang.String getBackImageFileName()
The public method getBackImageFileName returns the file name containing a PlayingCard's back image.
Specified by:
getBackImageFileName in interface Card
Returns:
the String value of the back image file name.

setBackImageFileName

public void setBackImageFileName(java.lang.String backImageFile)
The public method setBackImageFileName specifies the file name containing a PlayingCard's back image.
Specified by:
setBackImageFileName in interface Card
Parameters:
backImageFile - the String value of the back image file name.

getVisibility

public boolean getVisibility()
The public method getVisibility is used to retrieve the current state of a PlayingCard's visibility. The boolean true represents face up and the boolean false represents face down.
Specified by:
getVisibility in interface Card
Returns:
the boolean value representing the PlayingCard's visibility state.

setVisibility

public void setVisibility(boolean visible)
The public method setVisibility is used to set a PlayingCard's current state of visibility. Face up is represented by the boolean true and face down is represented by the boolean false. The default condition of a PlayingCard is face down.
Specified by:
setVisibility in interface Card
Parameters:
visible - the boolean value true (face up) or false (face down).

toString

public java.lang.String toString()
The public method toString returns the String representation of a PlayingCard, such as "Ace of Spades."
Specified by:
toString in interface Card
Overrides:
toString in class java.lang.Object
Returns:
the textual representation of a PlayingCard as a String.

equals

public boolean equals(Card theOtherPlayingCard)
The public method equals checks whether two PlayingCards have the same name and suit, and returns a boolean result.
Specified by:
equals in interface Card
Parameters:
theOtherCard - - the PlayingCard to be compared with this PlayingCard.
Returns:
the boolean result of the comparison.