Do you know what is wrong with my code? I want to initialize two-variable rank and suit together but I can only initialize 1.  Do you know how to initialize both to be able to run the program?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Do you know what is wrong with my code? I want to initialize two-variable rank and suit together but I can only initialize 1.  Do you know how to initialize both to be able to run the program?

 


import javax.swing.JOptionPane;

public class Lab3Q5 {

public static void main(String[] args) {
String suit;
String rank = JOptionPane.showInputDialog("Enter a Card");


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

rank = "Ace";

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

rank ="Two";

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

rank ="Three";

}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);
}
}

 

Expert Solution
Step 1: need more details

You have not provided the input-output format. so if you have specific input/output in mind. please repost again mentioning the format. I have assumed user input for the card as follows:

input: AD

Output: Ace of Diamond

input: 10H

Output: Ten of Hearts

input: H10

Output: Ten of Hearts

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education