logo Practice-It logo


Related Links:
Author: Marty Stepp

("Critter" classes come from the University of Washington's CSE 142 Critters homework assignment. See the assignment spec for more information.)

Write a class Minnow that extends Critter from the Critters homework assignment, along with its movement and eating behavior. All other aspects of Minnow use the defaults. Add fields, constructors, etc. as necessary to your class to implement this behavior.

Minnow objects initially move in a S/E/S/E/... pattern. However, when a Minnow encounters food (when its eat method is called), it should do all of the following:

  • Do not eat the food.
  • Start the movement cycle over. In other words, the next move after eat is called should always be South.
  • Lengthen and reverse the horizontal portion of the movement cycle pattern.
    The Minnow should reverse its horizontal direction and increase its horizontal movement distance by 1 for subsequent cycles. For example, if the Minnow had been moving S/E/S/E, it will now move S/W/W/S/W/W. If it hits a second piece of food, it will move S/E/E/E/S/E/E/E, and a third, S/W/W/W/W/S/W/W/W/W, and so on.

The following is an example timeline of a particular Minnow object's movement. The timeline below is also drawn in the diagram at right. Underlined occurrences mark squares where the Minnow found food. Notice how near the end of the Minnow's movement, it hits two pieces of food in a row, so it reverses from East to West and back again.

  • S, E, S, E (hits food)
  • S, W, W, S, W, W, S (hits food)
  • S, E, E, E, S, E, E, E, S, E (hits food)
  • S (hits food)
  • S, E, E, E, E, E, S, E, E, E, E, E, ...
Type your solution here:

This is an inheritance problem. Write a Java class using inheritance. (You do not need to write any import statements.)

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.