Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java please Write a modular program in a class called MagicBall that asks the user to enter a question and gives a Crystal Ball

in java please

image text in transcribed

image text in transcribed

Write a modular program in a class called MagicBall that asks the user to enter a question and gives a "Crystal Ball" like answer. e.g If the user enters "Will I get an A in the class", the answer may be "Hard work pays off!". The specifications are: - User repeatedly asks questions and terminates program by hitting enter - User can enter any question, valid or not (there is no input validation, strings are assumed) - The program reads answers from a file called "answers.txt" that you need to create with interesting answers. Each answer is on a separate line, You may use the sample file given. - The answers are stored in a one-dimensional string array called answers of SIZE 20 (constant) - The main method calls two static methods called readAnswers() // read answers from file and store answers in array, keep count of actual number of elements. This number should be less than 20. playGame() I/ use a while loop to repeatedly ask user to enter a question // use a random number generator to generate a random integer between 0 I/ and count-1 to randomly select an answer from the array answer // Random rand = new Random() creates a random object You will need to import java.util.Scanner and java.io

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

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions

Question

When there was controversy, was it clear who had the final say?

Answered: 1 week ago