program4
Class Card

java.lang.Object
  extended by program4.Card
Direct Known Subclasses:
GoFishCard

public class Card
extends java.lang.Object

Title: The Card Class

Description: Defines the properties and behaviors of a single playing card.

Copyright: Copyright (c) 2010

Version:
0.9
Author:
F. Graham

Field Summary
private  int rank
          rank - an integer between 0 - 12 representing the card
private  int suit
          suit - an integer between 0 - 3 representing the card
 
Constructor Summary
Card()
          Card default constructor -- gets called when an object of the Card class is instantiated -- rank and suit are randomly defined
Card(int n)
          Card constructor -- gets called when an object of the Card class is instantiated -- based upon the number received it determines the rank and suit of the card
Card(int r, int s)
          Card constructor -- gets called when an object of the Card class is instantiated -- r represents the rank, and s represents the suit of the card
 
Method Summary
 int compareByRank(Card otherCard)
          compareByRank -- this method compares 2 Card objects by rank and returns a negative integer, zero, or a positive integer as this Card is less than, equal to, or greater than the other Card.
For example the following call: card1.compareByRank(card2);
compares if the rank of card1 is greater than card2, is equal to card2, or is less than card2 and returns the appropriate value
 int compareBySuit(Card otherCard)
          compareBySuit -- this method compares 2 Card objects by suit and returns a negative integer, zero, or a positive integer as this Card is less than, equal to, or greater than the other Card.
For example the following call: card1.compareBySuit(card2);
compares if the suit of card1 is greater than card2, is equal to card2, or is less than card2 and returns the appropriate value
 boolean equals(Card otherCard)
          equals -- this method indicates whether some other Card is "equal to" this one.
 int getRank()
          getRank method -- returns what's stored in the instance variable rank
 java.lang.String getRankAsString()
          getRankAsString method -- returns a String representation of the instance variable rank
 int getSuit()
          getSuit method -- returns what's stored in the instance variable suit
 java.lang.String getSuitAsString()
          getSuitAsString method -- returns a String representation of the instance variable suit
 void setRank(int r)
          setRank method -- modifies the value of the instance variable rank
 void setSuit(int s)
          setSuit method -- modifies the value of the instance variable suit
 java.lang.String toString()
          toString method -- this method returns the state of the Card object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rank

private int rank
rank - an integer between 0 - 12 representing the card


suit

private int suit
suit - an integer between 0 - 3 representing the card

Constructor Detail

Card

public Card()
Card default constructor -- gets called when an object of the Card class is instantiated -- rank and suit are randomly defined


Card

public Card(int n)
Card constructor -- gets called when an object of the Card class is instantiated -- based upon the number received it determines the rank and suit of the card

Parameters:
n - a number between 0 and 51 that gets converted to a value between 0 and 12 for rank and a value between 0 and 3 for suit

Card

public Card(int r,
            int s)
Card constructor -- gets called when an object of the Card class is instantiated -- r represents the rank, and s represents the suit of the card

Parameters:
r - a number between 0 and and 12 representing the rank
s - a number between 0 and and 3 representing the suit
Method Detail

toString

public java.lang.String toString()
toString method -- this method returns the state of the Card object

Overrides:
toString in class java.lang.Object
Returns:
a reference to a string object that contains the values stored in the instance variables

setRank

public void setRank(int r)
setRank method -- modifies the value of the instance variable rank

Parameters:
r - a number between 0 and and 12 representing the rank

setSuit

public void setSuit(int s)
setSuit method -- modifies the value of the instance variable suit

Parameters:
s - a number between 0 and and 3 representing the suit

getRank

public int getRank()
getRank method -- returns what's stored in the instance variable rank

Returns:
the state of the instance variable rank

getSuit

public int getSuit()
getSuit method -- returns what's stored in the instance variable suit

Returns:
the state of the instance variable suit

getRankAsString

public java.lang.String getRankAsString()
getRankAsString method -- returns a String representation of the instance variable rank

Returns:
the state of the instance variable rank as a String

getSuitAsString

public java.lang.String getSuitAsString()
getSuitAsString method -- returns a String representation of the instance variable suit

Returns:
the state of the instance variable suit as a String

equals

public boolean equals(Card otherCard)
equals -- this method indicates whether some other Card is "equal to" this one.

Parameters:
otherCard - a reference to a Card object with which to compare
Returns:
true if this Card is the same as the otherCard; false otherwise.

compareByRank

public int compareByRank(Card otherCard)
compareByRank -- this method compares 2 Card objects by rank and returns a negative integer, zero, or a positive integer as this Card is less than, equal to, or greater than the other Card.
For example the following call: card1.compareByRank(card2);
compares if the rank of card1 is greater than card2, is equal to card2, or is less than card2 and returns the appropriate value

Parameters:
otherCard - a reference to a Card object
Returns:
negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the other Card.

compareBySuit

public int compareBySuit(Card otherCard)
compareBySuit -- this method compares 2 Card objects by suit and returns a negative integer, zero, or a positive integer as this Card is less than, equal to, or greater than the other Card.
For example the following call: card1.compareBySuit(card2);
compares if the suit of card1 is greater than card2, is equal to card2, or is less than card2 and returns the appropriate value

Parameters:
otherCard - a reference to a Card object
Returns:
negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the other Card.