Other 2012 FR Questions FR other years Be Prepared Home
public class RetroBug extends Bug 1
  private Location prevLocation = null; 2
  private int prevDirection;

  public RetroBug() 3
    setColor(Color.RED); 4

  public RetroBug(Color bugColor)
    setColor(bugColor); 5

  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)

  1. import statements are needed for the code to run but not required for full credit.
  2. = 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).
  3. 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 Bug's constructors.
  4. Or:
    or simply empty braces (super() is called by default).
  5. Or:
  6. That is, if act has not been called before.

Other 2012 FR Questions | Back to Contents

Copyright © 2012 by Skylight Publishing