logo Practice-It logo

Tigger

Related Links:
Author: Marty Stepp (on 2010/12/28)

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

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

Bouncing is what Tiggers do best! The Tigger's movement is to bounce up and down to increasingly large heights. A Tigger object is passed an integer when it is constructed that represents his initial bounce height. (You may assume that this bounce height is at least 1.) Whatever bounce height is passed, he will move that many steps NORTH, then that many steps SOUTH, then repeat for a bounce height 1 larger. For example, a new Tigger(4) will move NORTH 4 times, then SOUTH 4 times, then NORTH 5 times, then SOUTH 5 times, then NORTH 6 times, then SOUTH 6 times, and so on.

When a Tigger finds food, he eats it and completely starts over his bouncing behavior. That is, he starts over going NORTH on a bounce whose height is equal to the initial bounce height with which the Tigger was constructed. For example, the following would be a sequence of moves for a new Tigger(2) . Notice how he starts over every time he eats:

    N,N, S,S, N,N,N, S,S,S, N,N,N,N, S,S,S,S, N (eats food), N,N, S,S, N,N,N, S,S,S, N,N,N,N, ...
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.