logo CodeStepByStep logo

Raptor

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

Write a class Raptor that extends the Critter class, along with its movement behavior. All unspecified aspects of Raptor use the default behavior. Write the complete class with any fields, constructors, etc. necessary to implement the behavior.

In the absence of food, a Raptor moves horizontally. When a Raptor is constructed, he is passed a boolean value that indicates whether he will initially walk west (false) or east (true). The Raptor should remember this value and should continue walking in that direction until he finds food. If a Raptor finds food, he should eat it, and then "stomp" up and down 10 times by moving north-south 10 times. In other words, his next twenty moves after finding food should be N,S,N,S,N,S,N,S,N,S,N,S,N,S,N,S,N,S,N,S. After finishing his ten "stomps" the Raptor should resume moving horizontally, but reverse the direction from west to east or vice versa. For example, if the Raptor had been moving west and then finds food, he will move east once he is done stomping.

If two Raptor objects were constructed in the following way:

Raptor randy = new Raptor(false);
Raptor ryan  = new Raptor(true);

The following would be a possible sequence of moves for randy :

  • W,W,W,W,W,W (eats food), N,S,N,S,N,S,N,S,N,S,N,S,N,S,N,S,N,S,N,S, E, E, E, E, (eats food), N,S,...

The following would be a possible sequence of moves for ryan :

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