Ask Question
4 September, 16:41

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.

+2
Answers (1)
  1. 4 September, 17:47
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers