Write a program that takes user input describing a playing card in the following
ID: 3799558 • Letter: W
Question
Write a program that takes user input describing a playing card in the following shorthand notation: Your program should print the full description of the card. For example, Enter the card notation: QS Queen of Spades Implement a class Card whose constructor takes the card notation string and whose getDescription method returns a description of the card. If the notation string is not in the correct format, the getDescription method should return the string "Unknown". Write a program that reads in three floating-point numbers and prints the largest of the three inputs. For example:
Explanation / Answer
public class Card
{
private String denomination;
private String suite;
private String String1;
private String String2;
public Card(String s1)
{
denomination = s1.substring(0, 1);
suite = s1.substring(1);
}
public String getDescription()
{
if (denomination.equalsIgnoreCase("K"))
{
String1 = "King";
}
else if (denomination.equalsIgnoreCase("Q"))
{
String1 = "Queen";
}
else if (denomination.equalsIgnoreCase("J"))
{
String1 = "Jack";
}
else if (denomination.equals("10"))
{
String1 = "Ten";
}
else if (denomination.equals("9"))
{
String1 = "Nine";
}
else if (denomination.equals("8"))
{
String1 = "Eight";
}
else if (denomination.equals("7"))
{
String1 = "Seven";
}
else if (denomination.equals("6"))
{
String1 = "Six";
}
else if (denomination.equals("5"))
{
String1 = "Five";
}
else if (denomination.equals("4"))
{
String1 = "Four";
}
else if (denomination.equals("3"))
{
String1 = "Three";
}
else if (denomination.equals("2"))
{
String1 = "Two";
}
else if (denomination.equalsIgnoreCase("A"))
{
String1 = "Ace";
}
if (suite.equalsIgnoreCase("D"))
{
String2 = "Diamonds";
}
else if (suite.equalsIgnoreCase("H"))
{
String2 = "Hearts";
}
else if (suite.equalsIgnoreCase("C"))
{
String2 = "Clubs";
}
else if (suite.equalsIgnoreCase("S"))
{
String2 = "Spades";
}
return String1 + " of " + String2;
}
}
import java.util.*;
public class CardDescription
{
public static void main(String[] args)
{
Card c1 = new Card("KS");
System.out.println("Your card is " + c1.getDescription());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.