Ask Question
8 April, 20:29

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.

+5
Answers (1)
  1. 8 April, 21:22
    0
    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);

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a piece of code that reads a shorthand text description of a playing card and prints the longhand equivalent. The shorthand ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers