Question: Create a MultiGreeter class with the following capabilities: Feature Signature Requirement Constructors MultiGreeter() No-argument constructor; creates a MultiGreeter with maxGreetings = 1 MultiGreeter(int maxGreetings) Creates
Create a MultiGreeter class with the following capabilities:
| Feature | Signature | Requirement |
| Constructors | ||
|
| MultiGreeter() | No-argument constructor; creates a MultiGreeter with maxGreetings = 1 |
|
| MultiGreeter(int maxGreetings) | Creates a greeter that can hold up to maxGreetings greeting strings. Precondition: 0 < maxGreetings <= 255 |
| Methods | ||
|
| getMaxGreetings() : int | Returns the value maxGreetings, the maximum number of greetings this Greeter can hold |
|
| getNumGreetings(): int | Returns the number of greetings added to this MultiGreeter. |
|
| addGreeting(String greeting) : boolean | If Greeter already has maxGreetings added, the greeting will not be added and the method will return false; otherwise the method will add the given greeting to its collection of greetings and return true. |
|
| getGreetings(): String [] | Returns an array containing the greeting strings added to this Greeter in no particular order whose length is equal to the number of greetings added. |
|
| greet(String name) : String | Returns a salutation in the form greetingString, name!, where greetingString is one of the greeting strings added to the Greeter picked at random If no greetings were added to this MultiGreeter, uses the default greeting of Hello name a provided name. |
|
| greet() : String | Returns a salutation in the form greetingString, World!, where greetingString is one of the greeting strings added to the Greeter picked at random If no greetings were added to this MultiGreeter, uses the default greeting of Hello. |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
