Write a program that reads a 2-3 character string (which will be a shorthand not
ID: 3590366 • Letter: W
Question
Write a program that reads a 2-3 character string (which will be a shorthand notation describing a playing card) from the user and outputs the full description of the card To begin, you will get the string from the user. Input the string using a single nextLine command The inputted string will consist of a letter or number: (A, J, Q, K, 2, 3, 4, 5, 6, 7, 8, 9, or 10) followed by another letter: (D, H, S, c) After getting the input, your program should then print to the screen the full description of the card in the following format: VALUE of SUIT Number cards should NOT be spelled out - just display the number, face cards, however, do need to be spelled out. For example here are some possible input values, along with the expected output from the program If the user enters QS, your program should print: Queen of Spades If the user enters AH, your program should print: Ace of Hearts If the user enters 7C, your program should print: 7 of Clubs If the user enters 10D, your program should print: 10 of Diamonds If the user enters KC, your program should print: King of Clubs If the user enters JS, your program should print: Jack of Spades rogram runs. The The following is an example of what your MIGHT see on the screen when your p exact output depends on what values that the user types in while the program runs. Please be sure that you test ALL of the examples shown below with your program. The user's inputted values are shown below in italics Enter card abbreviation K King of Clubs Technical Notes & Requirements: You are NOT ALLOWED TO USE "IF" STATEMENTS in this program! You must create this program by using SWITCH statements instead o Create a variable called result o Use a SWITCH statement to assign the result variable an initial value the value of the card o Use a second SWITCH statement to concatinate to the result variable the card's suitExplanation / Answer
FindPlayingCard.java
import java.util.Scanner;
public class FindPlayingCard {
public static void main(String[] args) {
// Declaring variables
String card = null, suit = null, res = "";
String str;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
// Getting the input entered by the user
System.out.print("Enter the String :");
str = sc.nextLine();
int len = str.length();
//Based on the length of the string parse it
switch (len) {
case 2:
{
card = String.valueOf(str.charAt(0));
suit = String.valueOf(str.charAt(1));
break;
}
case 3:
{
card = str.substring(0, 2);
suit = String.valueOf(str.charAt(2));
break;
}
}
//finding the card and suit based on switch case
switch (card) {
case "A":
{
res += "Ace of ";
res += getSuit(suit);
break;
}
case "1":
{
res += "1 of ";
res += getSuit(suit);
break;
}
case "2":
{
res += "2 of ";
res += getSuit(suit);
break;
}
case "3":
{
res += "3 of ";
res += getSuit(suit);
break;
}
case "4":
{
res += "4 of ";
res += getSuit(suit);
break;
}
case "5":
{
res += "5 of ";
res += getSuit(suit);
break;
}
case "6":
{
res += "6 of ";
res += getSuit(suit);
break;
}
case "7":
{
res += "7 of ";
res += getSuit(suit);
break;
}
case "8":
{
res += "8 of ";
res += getSuit(suit);
break;
}
case "9":
{
res += "9 of ";
res += getSuit(suit);
break;
}
case "10":
{
res += "10 of ";
res += getSuit(suit);
break;
}
case "J":
{
res += "Jack of ";
res += getSuit(suit);
break;
}
case "Q":
{
res += "Queen of ";
res += getSuit(suit);
break;
}
case "K":
{
res += "King of ";
res += getSuit(suit);
break;
}
}
System.out.println(res);
}
private static String getSuit(String suit) {
String str = null;
switch (suit) {
case "D":
{
str = "Diamonds";
break;
}
case "H":
{
str = "Hearts";
break;
}
case "S":
{
str = "Spades";
break;
}
case "C":
{
str = "Clubs";
break;
}
}
return str;
}
}
_______________
Output#1:
Enter the String :QS
Queen of Spades
___________
Output#2:
Enter the String :AH
Ace of Hearts
__________
Output#3:
Enter the String :7C
7 of Clubs
__________
Output#4:
Enter the String :10D
10 of Diamonds
__________
Output#5:
Enter the String :KS
King of Spades
___________
Output#6:
Enter the String :JS
Jack of Spades
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.