A DancingCritter is a Critter that moves in the following manner. The DancingCritter makes a left turn if at least one of its neighbors is another DancingCritter. It then moves like a Critter. If none of its neighbors are DancingCrit ter objects, it moves like a Critter without making a left turn. In all other respects, a DancingCritter acts like a Critter by eating neighbors that are not rocks or critters. Consider the following implementations. (
Appendix )
I.
public class DancingCritter extends Critter
{
public ArrayList<Actor> getActors()
{
ArrayList<Actor> actors = new ArrayList<Actor>();
for (Actor a : getGrid().getNeighbors(getLocation()))
{
if (a instanceof DancingCritter)
actors.add(a);
}
return actors;
}
public void processActors(ArrayList<Actor> actors)
{
if (actors.size() > 0)
{
setDirection(getDirection() Location.LEFT);
}
super.processActors(actors);
}
II.
public class DancingCritter extends Critter
{
public void processActors(ArrayList<Actor> actors)
boolean turning = false;
for (Actor a : actors)
{
if (a instanceof DancingCritter)
turning = true;
}
if (turning) setDireCtion(getDirection() + Location.LEFT);
}
III.
public class DancingCritter extends Critter
{
public void makeMove(Location loc)
{
boolean turning = false;
for (Actor a : getGrid().getNeighbors(getLocation()))
{
if (a instanceof DancingCritter)
turning = true;
}
if (turning)
{
setDirection(getDirection() Location.LEFT);
}
super.makeMove(loc);
}
}
Which of the proposed implementations will correctly implement the DancingCritter class?
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and. III