public class RetroBug extends Bug 1
private Location prevLocation = null; 2
private int prevDirection;
public RetroBug() 3
public RetroBug(Color bugColor)
public void act()
prevLocation = getLocation();
prevDirection = getDirection();
public void restore()
if (prevLocation == null) 6
Actor neighbor = getGrid().get(prevLocation);
if (neighbor == null || neighbor instanceof Flower)
import statements are needed for the code to run but not required for full credit.
= null is optional: it is the default,
but the rules for default initialization are not in the AP subset.
It won't hurt if you add a redundant statement
prevLocation = null; to each constructor
(after a call to
super, if present).
- The question of whether any or what constructors are needed to receive
full credit will be answered at the AP Exam Reading in June.
Good style calls for two constructors for this class, similar to
super(); or simply empty braces (
super() is called by default).
- That is, if
act has not been called before.
Copyright © 2012 by Skylight Publishing