public class Card {

    public Card(String cardValue)
    	input = cardValue;
    public String getDescription()
    if (input.length() == 2)
    			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)
    			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";
    			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;



import javax.swing.JOptionPane;

public class CardTester
	public static void main(String[] args)
		String input = JOptionPane.showInputDialog("Enter the card notation");
		Card value = new Card(input);

You'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)

  first = "Ten of ";
else if(input.substring(2,3).equals("D"))
  third = "Diamonds";

Consider what the above code will do to the input "10D"

You should really consider using { } for your if-statements, it's good practice even though it's not needed

Edited 5 Years Ago by Slimmy: Clarification

What 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 to 60 to be below line 36 which is still inside the if(input.length()==2) scope.
3)Remove the variable "third" in line 68.

Edited 5 Years Ago by Taywin: n/a

This article has been dead for over six months. Start a new discussion instead.