THIS IS A JAVA PROGRAM - PLEASE COMMENT THE CODE Write a program that tests your
ID: 643058 • Letter: T
Question
THIS IS A JAVA PROGRAM - PLEASE COMMENT THE CODE
Write a program that tests your ESP (extrasensory perception). The program should randomly select the name of a color from the following list of words:
Red, Green, Orange, Yellow
To select a word, the program can generate a random number. For example, if the number is 0, the selected word is Red; if the number is 1, the selected word is Green; and so forth.
Next, the program should ask the user to enter the color that the computer has selected. After the user has entered his or her guess, the program should display the name of the randomly selected color. The program should repeat this 10 times and then display the number of times the user correctly guessed the selected color. Be sure to modularize the program into methods that perform each major task.
Explanation / Answer
static List choices = Lists.newArrayList("red", "green", "orange", "", "yellow"); public static 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 e.equals(input.toLowerCase())).findAny(); return val.isPresent(); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.