logo CodeStepByStep logo

Abby

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

Write a critter class Abby along with its movement and eating behavior. All unspecified aspects of Abby use the default behavior. Write the complete class with any fields, constructors, etc. necessary to implement the behavior.

Appearance: An Abby object should be displayed on the screen as an "@" at-sign.

Movement: An Abby object generally moves in an upward zigzag pattern, going east four times, north once, west four times, north once, and repeating:

  • E, E, E, E, N, W, W, W, W, N, E, E, E, E, N, W, W, W, W, N, ...

Eating: When an Abby finds food, she eats it. Eating causes Abby to slow down for a while, so that her next 3 regular moves are each preceded by a single turn without moving, indicated by a move of Direction.CENTER. (Note that this is unrelated to the simulator's putting critters to "sleep" when they eat; ignore sleeping and think about the next moves that your critter will be asked to make after eating.)

  • E, E, E, E, N, W, W (eats), C, W, C, W, C, N, E, E, E, E, N (eats), C, W, C, W, C, W, W, N, ...

If the Abby eats food again in the middle of this three-move slowdown sequence, the slow-down process starts over so that her next three moves are each preceded by a single turn moving to the CENTER. For example:

  • E, E, E, E, N, W, W (eats), C, W, C, W (eats), C, N, C, E, C, E, E, E, N, W, W, W, W, N, ...
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.