|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectprogram4.Card
public class Card
Title: The Card Class
Description: Defines the properties and behaviors of a single playing card.
Copyright: Copyright (c) 2010
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 |
---|
private int rank
private int suit
Constructor Detail |
---|
public Card()
public Card(int n)
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 suitpublic Card(int r, int s)
r
- a number between 0 and and 12 representing the ranks
- a number between 0 and and 3 representing the suitMethod Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public void setRank(int r)
r
- a number between 0 and and 12 representing the rankpublic void setSuit(int s)
s
- a number between 0 and and 3 representing the suitpublic int getRank()
public int getSuit()
public java.lang.String getRankAsString()
public java.lang.String getSuitAsString()
public boolean equals(Card otherCard)
otherCard
- a reference to a Card object with which to compare
public int compareByRank(Card otherCard)
otherCard
- a reference to a Card object
public int compareBySuit(Card otherCard)
otherCard
- a reference to a Card object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |