Question
In Java Write a program that tests your ESP (extrasensory- perception!. The program should randomly select the name of a color from the following list
In Java
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, Blue, 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 l t the selected word is Green; and so forth.
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 user choice
a message indicating if the user's choice was correct and how many times the user has been correct.
The program should repeat this 10 times
The program should have the following methods.
public static void main(String[] args)
public static String computerChoice() - randomly chooses a color
public static String userChoice()
prompts the user to select a color
calls isValidChoice to determine if the color is a valid color (Red, Green, Blue, Orange or Yellow)
If not a valid color reprompts the user for a valid color.
public static boolean isValidChoice(String aChoice)
Test the parameter aChoice to determine if it is a valid color
Returns true if valid, false if not.
Challenge - use an Enum to handle the colors.
Sample run
I'm thinking of a color. Is it red, green, blue, orange, or yellow? green Computer's Choice: GREEN User's Choice: GREEN
Choice 1 was correct Number of correct guesses: 1
I'm thinking of a color. Is it red, green, blue, orange, or yellow? blue Computer's Choice: RED User's Choice: BLUE
Choice 2 was incorrect Number of correct guesses: 1
I'm thinking of a color. Is it red, green, blue, orange, or yellow? purple Invalid choice I'm thinking of a color. Is it red, green, blue, orange, or yellow?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started