Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HELP MY CODE: ------------------------------------------------------------------------------------------------------------------------------------------------------------ import java.util.*; public class CardConverter { public static void main(String[] args) { Scanner kbd = new Scanner(System.in); //Declaring variables for ipnut

HELP MY CODE:

------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;

public class CardConverter {

public static void main(String[] args) { Scanner kbd = new Scanner(System.in); //Declaring variables for ipnut and output String input, result; char firstChar, secondChar; //Used as a space and output for switch result = ""; //Prompts the user to enter two abbreviations and stores the data into a string variable System.out.print("Enter card abbreviation: "); input = kbd.nextLine(); //Determines what character entered is which if(input.length()==3) { firstChar = input.charAt(0); secondChar = input.charAt(2); } else { firstChar = input.charAt(0); secondChar = input.charAt(1); } //Takes the inputted character and determines what to output switch(firstChar) { case 'A': result = "Ace"; break; case 'J': result = "Jack"; break; case 'Q': result = "Queen"; break; case 'K': result = "King"; break; case '2': result = "2"; break; case '3': result = "3"; break; case '4': result = "4"; break; case '5': result = "5"; break; case '6': result = "6"; break; case '7': result = "7"; break; case '8': result = "8"; break; case '9': result = "9"; break; case '1': result = "10"; break; } //Takes the second character that was inputted from the string to store it for printing. switch(secondChar) { case 'D': result = result + " of Diamonds"; break; case 'H': result = result + " of Hearts"; break; case 'C': result = result + " of Clubs"; break; case 'S': result = result + " of Spades"; break; } //Prints out the results System.out.println(" " + result); kbd.close(); } }

------------------------------------------------------------------------------------------------------------------------------------------------------------

image text in transcribed

HELP! MY CODE DOESN'T PRINT OUT ALL THE CORRECT OUTPUT!

FIRST IF THE USER INPUTS 8C, THE PROGRAM ONLY PRINTS "8", WHEN IT SHOULD PRINT "8 of Clubs"

SECOND: IF THE USER INPUTS a capital "J" and "c" such as "Jc" the program only prints out "Jack" and not "Jack of Diamonds" like it should.

THIRD: The program doesn't print out anything if the user enters j with any other letter combo.

the project 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 The following is an example of what your MIGHT see on the screen when your program runs. The 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: KC 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 resuit 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 suit You may assume that the input will be correct, and therefore you don't have to worry about adding any type of error handling possibilities

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions