Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Magic 8-Ball is a toy used forfortune-telling or seeking advice, developed in the 1950s andmanufactured by Mattel. It is often used in fiction since

The Magic 8-Ball is a toy used forfortune-telling or seeking advice, developed in the 1950s andmanufactured by Mattel. It is often used in fiction since theanswer can sometimes be accurate, inaccurate, or statisticallyimprobable. (Wikipedia)



Assignment:

Create a Magic8Ball class with the followingcapabilities:

Feature

Signature

Requirement

Constructors

public Magic8Ball(String [] answers)

Creates a Magic 8 Ball initialized with the answers provided inthe given array. The answers are added to the Magic 8 Ball in theorder they appear in the array.

public Magic8Ball()

Creates a Magic 8 Ball with no added answers.

Methods

public String [] getAnswers()

Returns a list of answers. The order of answers will correspondto the order added to the Magic 8 Ball.

If no answers were added to this Magic 8 Ball, the method willreturn an array with length 0.

public void addAnswer(String answer)

Adds a new answer to the list of answers of this Magic 8Ball.

public String getAnswer()

Returns a random answer from the list of answers added to thisMagic 8 Ball.

If this Magic8Ball has no added answers the method with return“YES” or “NO” randomly.

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

Financial Accounting

Authors: Robert Libby, Patricia Libby, Daniel Short, George Kanaan, M

5th Canadian edition

9781259105692, 978-1259103285

More Books

Students also viewed these Programming questions