logo CodeStepByStep logo

Elephant

("Critter" classes come from Marty Stepp's "Critters" homework assignment. See "Critters spec" link above for more information.)

Define a Critter class named Elephant with the following behavior:

constructor public Elephant(Attack attack)
(attack will be one of Attack.ROAR, Attack.POUNCE, or Attack.SCRATCH)
color gray (Color.GRAY)
eating behavior upon birth, decides either to always eat (true) or never eat (false) throughout its lifetime
fighting behavior uses the attack that was passed to the constructor
movement behavior prefers to move west if it is not in the horizontal center of the world;
otherwise, prefers north if it is not in the vertical center of the world;
but will not move onto a square occupied by another Elephant
toString "J" if this Elephant is hungry (if eat would return true); otherwise "j"
Inheritance: Write a Java class using inheritance.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.