75.0k views
3 votes
Write a piece of code that reads a shorthand text description of a playing card and prints the longhand equivalent. The shorthand description is the card's rank (2 through 10, J, Q, K, or A) followed by its suit (C, D, H, or S). You should expand the shorthand into the form "Rank of Suit". You may assume that the user types valid input.

User Doug Amos
by
7.3k points

1 Answer

5 votes

Answer:

The following code are:

Scanner console=new Scanner (System.in);

System.out.print("Enter a card: ");

String rank=console.next();

String suit=console.next();

if (rank.equals("2")) {

rank = "Two";

}else if (rank.equals("3")){

rank ="Three";

}else if (rank.equals("A")){

rank ="Ace";

}else if (rank.equals("4")){

rank ="Four";

}else if (rank.equals("5")){

rank ="Five";

}else if (rank.equals("6")){

rank ="Six";

}else if (rank.equals("7")){

rank ="Seven";

}else if (rank.equals("8")){

rank ="Eight";

}else if (rank.equals("9")){

rank ="Nine";

}else if (rank.equals("10")){

rank ="Ten";

}else if (rank.equals("J")){

rank ="Jack";

}else if (rank.equals("K")){

rank ="King";

}else {

rank ="Queen";

}

if (suit.equals("D")){

suit="Diamonds";

}else if(suit.equals("S")){

suit="Spades";

}else if(suit.equals("C")){

suit="Clubs";

}else {

suit="Hearts";

}

System.out.print(rank+" of "+suit);

Step-by-step explanation:

Firstly, we have create an object of Scanner class is "console" then we print a message for user is "Enter a card" and then follow the question.

User Shonzilla
by
7.2k points