Q Search October 18, 2017 at 1:56 PM Class and methods to write in this assignme
ID: 3595232 • Letter: Q
Question
Q Search October 18, 2017 at 1:56 PM Class and methods to write in this assignment the class must 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 word "quit" to exit the program. Given the hand, the program should identily what kind of poker hand the user enters, and print the type of hand on the console. There are five types of hands that your program should recognize Your program can assume that each input is a legal five-card poker hand from one of five possiblities, or the word "quit', so your pair, three of a kind, flush, full house, and four of a kind program does not need to recognize and recover from ilegal inputs. An example run of the program might look like the following, with the user input in italics: Qs7s2s4s5s flush 7h8hKsTs8s pair 2h4d2d4s4c full house KsKhKc8sKd four of a kind 3s9hTh9s9d three of a kind quit 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
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class PockerHand {
public static List<String> exactStrings(ArrayList<String> al){
ArrayList<String> exactList=new ArrayList<String>();
for(int i=0;i<al.size();i++)
{
int flag=1;
for(int j=0;j<al.get(i).length();j++){
char ch=al.get(i).charAt(j);
if(Character.isDigit(ch)) {
flag=0; break;
}
}
if(flag==1) exactList.add(al.get(i));
}
return exactList;
}
public static void main(String[] args) {
ArrayList<String> al=new ArrayList<String>();
Scanner scn=new Scanner(System.in);
do{
String input=scn.nextLine();
if(!input.equalsIgnoreCase("quit")) al.add(input);
else break;
}while(true);
List<String> result=exactStrings(al);
// System.out.println(al);
// System.out.println(result);
for(int i=0;i<result.size()-1;i++){
System.out.print(result.get(i)+", ");
}
System.out.print("and "+result.get(result.size()-1));
}
}
/*
output:-
haii
sdfsd7scjsd
sdcszvx7s5cz
zc cxzv9c7xz
teja
quit
[haii, sdfsd7scjsd, sdcszvx7s5cz, zc cxzv9c7xz, teja]
[haii, teja]
haii, and teja
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.