Олимпиадный тренинг

Задача . 34760


Задача

Темы:
 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 
 

time 1000 ms
memory 32 Mb
Правила оформления программ и список ошибок при автоматической проверке задач

Статистика успешных решений по компиляторам
Комментарий учителя