GiraffeCritter free response practice question

Note: GridWorld will not be featured on the 2015 and subsequent AP CS Exams.

One of the four free response problems on each AP Computer Science Exam references the GridWorld Case Study. Previous problems have required students to write the complete class for a creature that extends Critter.

Problem description

This question involves reasoning about the GridWorld case study. Reference materials are provided in the Quick Reference.

Assume that the following 3 lines are in the GiraffeCritter class. You do not need to copy these lines when you write the GiraffeCritter class.

public static final int STOMACH_SIZE = /* a positive number */;
public static final int NECK_SIZE = /* a positive number */;
public static final int MAX_HUNGRY_STEPS = /* a positive number */;

A GiraffeCritter is a Critter that eats flowers to survive. Each time the GiraffeCritter acts, it attempts to eat STOMACH_SIZE flowers from the area within NECK_SIZE rows and NECK_SIZE columns. The GiraffeCritter eats a flower by removing it from the grid.

If the GiraffeCritter is able to eat STOMACH_SIZE flowers in a step, it remains at the same location for the step. If the GiraffeCritter is unable to eat STOMACH_SIZE flowers in a step, it moves like a Critter. If the GiraffeCritter is unable to eat STOMACH_SIZE flowers for MAX_HUNGRY_STEPS consecutive steps, it removes itself from the grid.

Write the complete GiraffeCritter class, including all instance variables and required methods. Do NOT override the act method. Remember that your design must not violate the postconditions of the methods of the Critter class and that updating an object’s instance variable changes the state of that object.

The processActors method of the Critter class illustrates how to check if an actor is an instance of a class.

See the GiraffeCritter solution and explanation or review it with AP CS Tutor Brandon Horn.

Get AP CS Help

GridWorld Practice Problems

GridWorld Case Study Explanations

Leave a Reply