/ Published in: Java
this programming convert number and key word to a sentence. however, it still has a problem about if statement, when i add else after the if statement every time it executes so every result became in the else statement one. [UPDATED] Now it runs, I added another huge contents of if statement.
Expand |
Embed | Plain Text
/** write a programming that takes user input describing a playing card in the followint shorthand notaiton (see text p221) Your program should print the full description of the card. 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" */ import java.util.Scanner; public class card { public String notation; //public int key; /** this function is input number and return int value */ { notation = in.next(); return notation; } /** this function has an error seems like confuse to return value this function supposed to take a string and return the string to main function */ public int getScriptionS() { int key = in.nextInt(); return key; } { /** A : Ace, 2 to 10 :card value J : Jack, Q : Queen K : King, D : Diamond H : Heart, S : Spades C : Clubs */ if( inputData.equals("A") || inputData.equals("J") || inputData.equals("Q") || inputData.equals("K") || inputData.equals("D") || inputData.equals("H") || inputData.equals("S") || inputData.equals("C")) { if (inputData.equals("A")) mean = " of Ace"; if (inputData.equals("J")) mean = " of Jack"; if (inputData.equals("Q")) mean = " of Queen"; if (inputData.equals("K")) mean = " of King"; if (inputData.equals("D")) mean = " of Dianomd"; if (inputData.equals("H")) mean = " of Hearts"; if (inputData.equals("S")) mean = " of Spades"; if (inputData.equals("C")) mean = " of Clubs"; } else {mean = "Unknown";} return mean; } { if((inputData2 <= 13) || (inputData2 >= 1)) { if(inputData2 == 1) {data4 = "One";} if(inputData2 == 2) {data4 = "Two";} if(inputData2 == 3) {data4 = "Three";} if(inputData2 == 4) {data4 = "Four";} if(inputData2 == 5) {data4 = "Five";} if(inputData2 == 6) {data4 = "Six";} if(inputData2 == 7) {data4 = "Seven";} if(inputData2 == 8) {data4 = "Eight";} if(inputData2 == 9) {data4 = "Nine";} if(inputData2 == 10) {data4 = "Ten";} if(inputData2 == 11) {data4 = "Eleven";} if(inputData2 == 12) {data4 = "Twelve";} if(inputData2 == 13) {data4 = "Thrteen";} } else {data4 = "Unknown";} return data4; } { card userInput = new card(); int data2; input = userInput.getScription(); // String data2 = userInput.getScriptionS(); // int cardName = getNotation(input); // String data3 = getNotation2(data2); // int } }
You need to login to post a comment.
