logo CodeStepByStep logo

Ostrich

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

Write a complete Critter class named Ostrich, including its movement and color behavior.

An Ostrich object first stays in the same place for 10 moves, then moves 10 steps to either the west or the east, then repeats. In other words, after sitting still for 10 moves, the ostrich randomly picks to go west or east, then walks 10 steps in that same direction. Then it stops and sits still for 10 moves and repeats. Whenever an Ostrich is moving (that is, initially and whenever its last call to getMove returned a direction other than Direction.CENTER), its color should be white (Color.WHITE). As soon as it stops moving, and initially when it is placed into the critter world, its color should be cyan (Color.CYAN). When randomly choosing west vs. east, the two directions should be equally likely.

You may add anything needed (fields, other methods) to implement the above behavior appropriately. All other behavior not discussed here uses the default values.

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.