Answered step by step
Verified Expert Solution
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
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.ioStep 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