static List choices = Lists.newArrayList(\"red\",
\"green\", \"blue\", \"orange\", \"yellow\", \"violet\");
public ststic void main(String[] args)
{
int correctGuesses = 0;
String input;
Scanner Keyboard = new Scanner(System.in);
//join list for display
String colors = String.join(\", \", choices);
//play the game for 10 rounds.
for(int round = 1;round<=10; round++)
{
Sysyem.out.print(\"my predition of the color is \" + colors +
\":\");
input = keyboard.next();
while(!isValidChoice(input)) {
System.out.print(\"Please enter \" + colors+ \":\");
input = keyboard.next();
}
if(computerChoice().equalsIgnoreCase(input))
{
correctGuesses ++;
}
}
Keyboard.close();
System.out.println(\"Number of correct guesses: \"
+correctGuesses);
}
static String computerChoice()
{
Random random = new Random();
OptionalInt computerChoice = random.ints(0, choices.size()
-1).findFirst();
return choices.get(computerChoice.getAsInt());
}
static boolean isValidChoice(String input)
{
java.util.Optional val = choices.stream().filter(e
-> e.equals(input.toLowerCase())).findAny();
return val.isPresent();
}