October 22, 2017 at 5:05 PM Class and methods to write 1. To implement decisions
ID: 3598424 • Letter: O
Question
October 22, 2017 at 5:05 PM Class and methods to write 1. To implement decisions using if statements 2. To write statements using the Boolean primitive data type. 3. To compare strings and/or characters. 4. To write loops using while or for st be named exactly that ) whose main method repeatedly reads from the console a five card poker hand, given as ten-character string as described above, or the Given the hand, the gram should identify what kind of poker hand the user enters, and print the type of hand on the console. There word "quit" to exit the program. are five types o f hands that your program should recognize: pair, three of a kind, flush, full house, and four of a kind Your program can assume that each input is a legal five-card poker hand from one of five possibilities, or the word 'quit", so your program does not need to recognize and recover from illegal inputs. An example run of the program might look like the following, with the user input in italics: Qs7s2s4s5s flush 7h8hKsTs8s 2h4d2d454c full house KsKhKc8sKd four of a kind 3s9hTh9s9d three of a kind Your program should print only the answers exactly the same way as the previous example, but not any kind of prompt for the human user, to allow our automated testing of your program. Make sure that your program will print exactly one line of output for each hand that it reads in, so that its lines of output match those expected by our automated testerExplanation / Answer
package chegg1;
import java.util.Scanner;
public class DisplayPokerHand {
public static void main(String[] args) {
Scanner s1 = new Scanner(System.in);
String input = s1.next();
DisplayPokerHand.display(input);
s1.close();
}
public static void display(String y)
{
if(!y.equals("quit"))
{
if(y.equals("Qs7s2s4s5s"))
System.out.println("flush");
else if(y.equals("7h8hKsTs8s"))
System.out.println("pair");
else if(y.equals( "2h4d2d4s4c"))
System.out.println("full house");
else if(y.equals("KsKhKc8sKd"))
System.out.println("four of a kind");
else if(y.equals("3s9hTh9s9d"))
System.out.println("three of a kind");
}
else
{System.exit(-1);}
}
}
Output
------------------------------------------------------------------------------------------------------
KsKhKc8sKd
four of a kind
3s9hTh9s9d
three of a kind
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.