logo CodeStepByStep logo

Frog

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

Define a Critter class named Frog with the following behavior:

constructor public Frog(int age)
The age passed will be between 1 and 9 inclusive.
color green
eating behavior never eats (this is the default eating behavior)
fighting behavior always forfeits in a fight (this is the default fighting behavior)
movement behavior moves east sometimes, or stays put (center), based on the frog's age:

If the frog is 1 year old, moves to the east every move.
E, E, E, E, E, E, E, E, E, E, ...

If the frog is 2 years old, moves to the east once every 2 moves.
C, E, C, E, C, E, C, E, C, E, ...

If the frog is 3 years old, moves to the east once every 3 moves.
C, C, E, C, C, E, C, C, E, C, ...

...

If the frog is 9 years old, moves to the east once every 9 moves.
C, C, C, C, C, C, C, C, E, C, ...

toString "F"
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.