Note: GridWorld will not be featured on the 2015 and subsequent AP CS Exams.
RockHound processes actors differently than Critter so it must override processActors. Overriding the correct methods of Critter is commonly tested on the AP Computer Science Free Response.
Review the RockHound solution with AP CS Tutor Brandon Horn.
RockHound
public class RockHound extends Critter
{
/**
* Removes all rocks in actors from the grid.
*/
public void processActors(ArrayList<Actor> actors)
{
for(Actor actor : actors)
if(actor instanceof Rock)
actor.removeSelfFromGrid();
}
}
My Critter Class Explanation covers each Critter method including the postcondition, the default implementation, and when the method should be overridden.
AP CS GridWorld Case Study Solutions |
Recommended Practice Problems |