Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions