Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that takes user input describing a playing card in the following

ID: 3624887 • Letter: W

Question

Write a program that takes user input describing a playing card in the following shorthand notation:

Notation



Meaning





A



Ace





2 … 10



Card values





J



Jack





Q



Queen





K



King





D



Diamonds





H



Hearts





S



Spades





C



Clubs


Your program should print the full description of the card. For example,

Enter the card notation:
4S
Four 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".
Use the following class as your main class:

import java.util.Scanner;

/**
This is a test for the Card class, which outputs the full
description of a deck of cards.
*/
public class CardPrinter
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

System.out.println("Enter the card notation:");
String input = in.nextLine();
Card card = new Card(input);
System.out.println(card.getDescription());
}
}



You need to supply the following class in your solution:

Card

Explanation / Answer

public class Card
{

private String num;
private String equal;

public Card(int num, String equal)
{
if (equal == "A") 
  { 
     this.equal = " of Ace"; 
  } 
else if (equal == "J") 
   { 
     this.equal = "of Jack"; 
   } 
else if (equal == "Q") 
   { 
     this.equal = "of Queen"; 
   } 
else if (equal == "K") 
   { 
      this.equal = "of King"; 
   } 

else if (equal == "D") 
  { 
     this.equal = "of Diamonds"; 
  } 
else if (equal == "H") 
   { 
     this.equal = "of Hearts"; 
   } 
else if (equal == "S") 
   { 
     this.equal = "of Spades"; 
   } 
else if (equal == "c") 
   { 
      this.equal = "of Clubs"; 
   } 

else 
   {  
     this.equal = "Unknown ";  
   }  
if (num == 2)  
   {  
    this.num = "Two ";  

   }  

else if (num == 3)  
   {  
    this.num = "Three ";  

   }  

else if (num == 4)  
   {  
    this.num = "Four ";  

   }  
else if (num == 5)  
   {  
    this.num = "Five ";  

   }  
else if (num == 6)  
   {  
    this.num = "Six";  

   }  
else if (num == 7)  
   {  
    this.num = "Seven ";  

   }  
else 
   {  
     this.equal = "Unknown ";  
    }   
 

}
      
public String getDescription()
   { 
       return this.num + this.equal; 
    }  
    

 }

 

 

/**
This is a test for the Card class, which outputs the full
description of a deck of cards.
*/
public class CardPrinter
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

System.out.println("Enter the card notation:");
String input = in.nextLine();
Card card = new Card(input);
System.out.println(card.getDescription());
}
}

 

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote