Design a program using Raptor Flowcharts that tests your ESP, or extrasensory perception. The program will randomly...

Free

60.1K

Verified Solution

Question

Programming

Design a program using RaptorFlowcharts that tests your ESP, or extrasensoryperception. The program will randomly pick a color from Red, Green,Blue, Orange, Yellow, and Purple, and you will be asked to predictthe program's selection before it is revealed. The program shouldask the user to enter the color the computer has selected. Theprogram should ensure user enters only one of the six colors. Afteruser has entered his or her guess, the program should display thename of the randomly selected color. The program should repeat this10 times and then display the number of times the user correctlyguessed the selected color.  

Answer & Explanation Solved by verified expert
4.5 Ratings (992 Votes)

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();

}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students