Question
Animal (interface) void eat(String food) void walk() void speak() Predator (interface) void chase(Animal a) Prey (used as a marker to mark which animal is a
Animal (interface)
void eat(String food)
void walk()
void speak()
Predator (interface)
void chase(Animal a)
Prey (used as a marker to mark which animal is a prey)
body is empty
Friendly(used as a marker to mark which animal is friendly)
body is empty
AbstractAnimal (abstract class)
fields or instance variables
o String name
methods
o constructors, set and get methods
o eat(String food) - print the name of the animal is eating the food. Example, "Kitty is eating cheese."
o walk() - print the name of the animal is walking. Example, "Kitty is walking."
o speak() is abstract method to be implemented by subclass
Human (is friendly)
speak() prints the name , the action, and the sound it makes. . Example, "Joe says blah blah."
Mouse (is a prey)
speak() prints the name , the action, and the sound it makes. Example, "Micky says squeak squeak."
Cat (is friendly and is a predator)
speak() prints the name , the action, and the sound it makes. Example, "Kitty says moew."
chase(Animal a) prints the name of the animal doing the chasing, the action, and the name of the animal being chased. Example, "Kitty is chasing Mickey." A cat only chases Prey. If the animal is not a prey, print print "Kitty runs away from Joe." if Joe is not a prey.
Main class
how to create some random animals of Cat, Dog, and human. You can manually create them or use Random class to help you create the random objects. Store them in an array.
Using the array, make all the animals walk.
Using the array, make all the friendly animals speak.
Using the array, make each predator chase all the preys in the array.
Sample run:
All animals in the zoo. Boomer is a cat. Bob is a human. Mickey is a mouse. Kitty is a cat. Making all animals walk. Boomer is walking. Bob is walking. Mickey is walking. Kitty is walking. Making all friendly animals speak. Boomer says meow. Bob says blah blah. Kitty says meow. Making all predators chase all preys. Boomer is running away from Bob. Boomer is chasing Mickey. Boomer is running away from Kitty. Kitty is running away from Boomer. Kitty is running away from Bob. Kitty is chasing Mickey. |
Step 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