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

I need help writting this program I am totally lost with how to do this. It woul

ID: 3676407 • Letter: I

Question

I need help writting this program I am totally lost with how to do this. It would be awesome if you can explain how to do it with comments.

Write a complete program 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. You must have two methods in addition to

the main method.

YOU MUST USE APPROPRIATE METHOD NAMES, PROPER INDENTATION, AND CORRECT LOGIC

Main method: Create a Scanner object, call Method 3. No output can be produced in the main. Your main method must only have two lines of code.

                        Create the Scanner object

                        Call method 3

Method 1: Get the Scanner object as its parameter then this method reads the card’s rank and returns its longhand equivalent as a String.

Method 2: Gets the Scanner object as its parameter, this method then gets the suit value form the user and return the long hand form of the suit. .

Method 3: This method gets the Scanner object as its parameter. Then ask the user for the number of the cards that he/she has, create a for loop, within the for loop you must call methods1 and method 2, output the result for the user’s input.

Your program must work with lower case and upper case letters

Here is the sample execution:

How many cards do you have? 2

Enter your card’s rank: 9

Enter your card’s suit: S

Nine of Spades

Enter your card’s rank: K

Enter your card’s suit: c

King of Clubs

Explanation / Answer

Solution:

package com.nancy.chegg.qa;

import java.util.Scanner;

public class Cards {

   //Main function
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       method3(scan);
       scan.close();
   }

   //method3 which is intermediate function to achieve the result.
   private static void method3(Scanner scan) {
       System.out.println("How many cards do you have? ");
       //save the input int value entered by user on console.
       int num = scan.nextInt();
      
       //looping according to the inputed value.
       for(int i = 0; i< num ;i++) {
           String rank = method1(scan);
           String suit = method2(scan);
           System.out.println(rank + " of " + suit);
       }
   }

   //find the longhand of rank here.
   private static String method1(Scanner scan) {
       System.out.println("Enter your card’s rank: ");
      
       //save the rank entered in console.
       String temp = scan.next();
       String res = "";
      
       switch(temp.toUpperCase()) {//wheather input is in lowercase or uppercase we will convert it to uppercase
           case "1":
               res = "One";
               break;
           case "2":
               res = "Two";
               break;
           case "3":
               res = "Three";
               break;
           case "4":
               res = "Four";
               break;
           case "5":
               res = "Five";
               break;
           case "6":
               res = "Six";
               break;
           case "7":
               res = "Seven";
               break;
           case "8":
               res = "Eight";
               break;
           case "9":
               res = "Nine";
               break;
           case "10":
               res = "Ten";
               break;
           case "J":
               res = "Jack";
               break;
           case "Q":
               res = "Queen";
               break;
           case "K":
               res = "King";
               break;
           case "A":
               res = "Ace";
               break;
       }
      
       return res;
   }

   //find the longhand of suit here.
   private static String method2(Scanner scan) {
       System.out.println("Enter your card’s suit: ");
       //save the suit entered in console.
       String temp = scan.next();
       String res = "";
       switch(temp.toUpperCase()) {    //wheather input is in lowercase or uppercase we will convert it to uppercase
           case "C":
               res = "Clubs";
               break;
           case "D":
               res = "Diamonds";
               break;
           case "H":
               res = "Hearts";
               break;
           case "S":
               res = "Spades";
               break;
              
       }
       return res;
   }

}


Sample Output:

How many cards do you have?2
Enter your card’s rank:9
Enter your card’s suit:S
Nine of Spades


Enter your card’s rank:K
Enter your card’s suit:c
King of Clubs