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, ...