hi i have a logic error with my program. it returns and prints unknown for every value. have a look...
what should i even put in the constructor?
it prints unknown on every run!public class Card { public Card() { String value, suit; } /* getDescription method that takes * the user input and turns it into a longer string * or returns the string, "Unknown" * */ public String getDescription(String value) { String cardValue = value.substring(0,1); //breaking apart the suit from the value using the substring method if (cardValue.equalsIgnoreCase("A")) value = "Ace of "; else if (cardValue.equals("2")) value = "Two of "; else if (cardValue.equals("3")) value = "Three of "; else if (cardValue.equals("4")) value = "Four of "; else if (cardValue.equals("5")) value = "Five of "; else if (cardValue.equals("6")) value = "Six of "; else if (cardValue.equals("7")) value = "Seven of "; else if (cardValue.equals("8")) value = "Eight of "; else if (cardValue.equals("9")) value = "Nine of "; else if (cardValue.equals("1")) //only concerned about the first digit, so 1 will suffice for ten! value = "Ten of "; else if (cardValue.equalsIgnoreCase("J")) //using the method equalsIgnoreCase() to ensure reading the user's data properly value = "Jack of "; else if (cardValue.equalsIgnoreCase("Q")) value = "Queen of "; else if (cardValue.equalsIgnoreCase("K")) value = "King of "; else return "Unknown"; //end if //now I handle the problem of having the card 10 in the user input with the following if statement String suit; //string that will return the suit INTO the return value if (cardValue.equals("1")) suit = value.substring(2,3); else suit = value.substring(1,2); //end if //now this if statement discovers the suit if (suit.equalsIgnoreCase("D")) suit = "Diamonds"; else if (suit.equalsIgnoreCase("H")) suit = "Hearts"; else if (suit.equalsIgnoreCase("S")) suit = "Spades"; else if (suit.equalsIgnoreCase("C")) suit = "Clubs"; else return "Unknown"; //end if String fullDescription = value + suit; return fullDescription; } } public class CardTest { /** * this program runs the card class and prints a description of the user's card */ public static void main(String[] args) { Scanner in = new Scanner(System.in); Card card = new Card(); System.out.println("Enter a card and its suit like this (4S): "); String userInput = in.next(); System.out.println(card.getDescription(userInput)); } }