The Magic 8-Ball is a toy used forfortune-telling or seeking advice, developed in the 1950s andmanufactured by
Question:
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. |
Financial Accounting
ISBN: 978-1259103285
5th Canadian edition
Authors: Robert Libby, Patricia Libby, Daniel Short, George Kanaan, M