public class Card {
public Card(String cardValue)
{
input = cardValue;
}
public String getDescription()
{
if (input.length() == 2)
{
if(input.substring(0,1).equals("A"))
first = "Ace of ";
else if(input.substring(0,1).equals("2"))
first = "Two of ";
else if(input.substring(0,1).equals("3"))
first = "Three of ";
else if(input.substring(0,1).equals("4"))
first = "Four of ";
else if(input.substring(0,1).equals("5"))
first = "Five of ";
else if(input.substring(0,1).equals("6"))
first = "Six of ";
else if(input.substring(0,1).equals("7"))
first = "Seven of ";
else if(input.substring(0,1).equals("8"))
first = "Eight of ";
else if(input.substring(0,1).equals("9"))
first = "Nine of ";
else if(input.substring(0,1).equals("J"))
first = "Jack of ";
else if(input.substring(0,1).equals("Q"))
first = "Queen of ";
else if(input.substring(0,1).equals("K"))
first = "King of ";
else first = "Unknown of ";
}
if (input.length() == 3)
{
if(input.substring(0,2).equals("10"))
first = "Ten of ";
else if(input.substring(2,3).equals("D"))
third = "Diamonds";
else if(input.substring(2,3).equals("H"))
third = "Hearts";
else if(input.substring(2,3).equals("S"))
third = "Spades";
else if(input.substring(2,3).equals("C"))
third = "Clubs";
else third = "Unknown";
}
if(input.substring(1,2).equals("D"))
second = "Diamonds";
else if(input.substring(1,2).equals("H"))
second = "Hearts";
else if(input.substring(1,2).equals("S"))
second = "Spades";
else if(input.substring(1,2).equals("C"))
second = "Clubs";
else second = "Unknown";
return first + second;
}
private String first;
private String second;
private String third;
private String input;
}
TigerTeck
0
Light Poster
Recommended Answers
Jump to PostYou've got a couple of errors.
1. When the string is of length 3 you assign a variable "third" a value but this value is never returned.
2. Your if-else statements are wrong @ lines 40-42 (maybe somewhere else too)if(input.substring(0,2).equals("10")) first = "Ten of "; else …
Jump to PostWhat first, second, third, variable for? You are NOT returning "third" but first+second even though you assigned value to "third" in your checking?
You need to modify some in your codes...
1)Change all "third" variable name to "second" in line 43 to 50.
2)Move your code line 52 …
All 6 Replies
TigerTeck
0
Light Poster
Slimmy
0
Junior Poster in Training
TigerTeck
0
Light Poster
TigerTeck
0
Light Poster
Taywin
312
Posting Virtuoso
TigerTeck
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.