Question: (In Java) Write a Plant class with a name (string) attribute, a size attribute (initially 1), a grow method which increases the plant's size by
(In Java)
Write a Plant class with a name (string) attribute, a size attribute (initially 1), a grow method which increases the plant's size by 1, and a die method which destroys/deletes that Plant.
Write an Animal class with a name (string) attribute, a size attribute (initially 1), an eat method which takes either a Plant instance or an Animal instance as the argument and returns nothing, and a die method which destroys/deletes that Animal.
Write a Carnivore class which inherits from Animal. Its eat method should invoke die on the Plant or Animal eaten, and do the following:
If the object eaten was a Plant, the Carnivore should decrease its size by 1 (if it reaches 0, it should die).
If the object eaten was an Animal, it should increase its size by the size of the animal eaten.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
