Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program that simulates the Magic 8 Ball game. Upon running the program, generate a random number such that one of the following

Write a java program that simulates the Magic 8 Ball game. Upon running the program, generate a random number such that one of the following 8 responses is output:

It is certain It is decidedly so Most likely Signs point to yes Reply hazy, try again Ask again later Don't count on it My sources say no

There should be an equal chance for any one of the eight responses to come up. The program should ask the user if he or she would like to repeat the program and loop if the user opts to repeat. Random number generation is discussed more extensively in Chapter 6 of the textbook, but for this program you can use the following line of code to generate a random number between 1 and 8:

Random rng = new Random(); int answer = rng.nextInt(8) + 1;

Below is a sample transaction:

What question would you like to ask the Magic 8 ball? Will it rain today? [user input] The answer is: Don't count on it

Would you like to ask another question (type Y or N)? Y What question would you like to ask the Magic 8 ball? Am I doing well in life? [user input] The answer is: Signs point to yes

Would you like to ask another question (type Y or N)? N Thank you for playing the Magic 8 Ball.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago