M
moon
Hi All,
Im getting theh erorr variable might not have been initialized when
trying to compile below:
public class Card
{
private int rank;
private int suit;
//first private final string array
private final String [] strSuits = {"Clubs", "Hearts", "Diamonds",
"Spades"};
//second array to hold string ranks
private final String [] strRanks = {"Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Queen", "King", "Ace" };
//first static boolean test function
private static boolean isValidRank(int possibleRank)
{
if(possibleRank < 0 || possibleRank > 12)
{
return false;
}
return true;
}
//second boolean test function
private static boolean isValidSuit(int possibleSuit)
{
if(possibleSuit < 0 || possibleSuit > 3)
{
return false;
}
return true;
}
//test to see if incoming values is in a valid suit
public Card(int thisSuit, int thisRank)
{
if(isValidSuit(thisSuit))
{
suit = thisSuit;
}
else
{
suit = 0;
}
//test to see if value is in range
if(isValidRank(thisRank))
{
rank = thisRank;
}
else
{
rank = 0;
}
}
// two public methods
public int getRank()
{
return rank;
}
public int getSuit()
{
return suit;
}
//method to return string value
public String suitToString()
{
String suit = "Suit"+suit;
return suit;
}
//method to return rank string value
public String rankToString()
{
String rank = "Rank"+rank;
return rank;
}
}
any help would be great!Thanks!
moon
Im getting theh erorr variable might not have been initialized when
trying to compile below:
public class Card
{
private int rank;
private int suit;
//first private final string array
private final String [] strSuits = {"Clubs", "Hearts", "Diamonds",
"Spades"};
//second array to hold string ranks
private final String [] strRanks = {"Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Queen", "King", "Ace" };
//first static boolean test function
private static boolean isValidRank(int possibleRank)
{
if(possibleRank < 0 || possibleRank > 12)
{
return false;
}
return true;
}
//second boolean test function
private static boolean isValidSuit(int possibleSuit)
{
if(possibleSuit < 0 || possibleSuit > 3)
{
return false;
}
return true;
}
//test to see if incoming values is in a valid suit
public Card(int thisSuit, int thisRank)
{
if(isValidSuit(thisSuit))
{
suit = thisSuit;
}
else
{
suit = 0;
}
//test to see if value is in range
if(isValidRank(thisRank))
{
rank = thisRank;
}
else
{
rank = 0;
}
}
// two public methods
public int getRank()
{
return rank;
}
public int getSuit()
{
return suit;
}
//method to return string value
public String suitToString()
{
String suit = "Suit"+suit;
return suit;
}
//method to return rank string value
public String rankToString()
{
String rank = "Rank"+rank;
return rank;
}
}
any help would be great!Thanks!
moon