The StockpileCritter
problem from the 2009 AP Computer Science Exam is typical of free response problems that test GridWorld: The AP Computer Science Case Study. The problem requires you to extend the Critter
class, determine which methods to override, and implement the entire subclass.
StockpileCritter
is #2 from the 2009 AP Computer Science Free Response.
https://secure-media.collegeboard.org/apc/ap09_frq_computer_science_a.pdf
StockpileCritter
class
public class StockpileCritter extends Critter
{
private int stockpile = 0;
public void processActors(ArrayList<Actor> actors)
{
for(Actor a : actors)
{
a.removeSelfFromGrid();
stockpile++;
}
stockpile--;
}
public Location selectMoveLocation(ArrayList<Location> locs)
{
if(stockpile < 0)
return null;
else
return super.selectMoveLocation(locs);
}
}
2009 AP CS Exam Free Response Solutions
- NumberCube Free Response Solution
- BatteryCharger Free Response Solution
- TileGame Free Response Solution
Help & comments
Get help from AP CS Tutor Brandon Horn