Project 22-2 Animal List
Project 22-2: Animal List
Create an application that collects and displays various animals.
Console
Welcome to the Animal List
Type of animal:
1 – Dog
2 – Cat
3 – Turtle
Choose type: 2
Enter animal’s name: Percy
Continue? (y/n): y
Type of animal:
1 – Dog
2 – Cat
3 – Turtle
Choose type: 3
Enter animal’s name: Yertle
Continue? (y/n): n
And now let’s hear the animals speak
————————————
Percy the Cat says ‘Meow’
Yertle waves! (turtles don’t have vocal cords)
Specifications
Create an abstract class named Animal. This class should have a private name variable of type String, and contain these constructors and methods:
public Animal(String name)
public String getName()
public void setName(String name)
public String getNameAndType()
public abstract void speak()
protected void speak(Consumer<Animal> consumer)
The getNameAndType() method should return the animal’s name concatenated with ‘the’ and the type of the class (example: ‘Percy the Cat’).
Create subclasses named Dog, Cat, and Turtle that extend the Animal class. These classes should have constructors that call the constructor of the parent class.
When the subclasses override the abstract speak() method, they should call the protected speak() method of the parent class and pass it a function. This function contains the functionality for the speak() method for that subclass.
You should be able to easily modify this class so an animal ‘speaks’ by printing data to the console or by displaying a GUI dialog box.
After the user has entered all the animals they want, each animal that they’ve entered should ‘speak’.
Use the Console class from chapter 7 or a variation of it to validate the user’s input.
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.