Director free response answer 2

Director free response problem from the 2014 AP Computer Science A Exam.

Director is #2 from the from the 2014 AP Computer Science A Free Response problems.

http://media.collegeboard.com/digitalServices/pdf/ap/ap14_frq_computer_science_a.pdf

Director class

public class Director extends Rock
{
    public Director()
    {
        super(); // not required since Rock has a default constructor
        setColor(Color.RED);
    }
    
    public void act()
    {
        if(Color.GREEN.equals(getColor()))
        {
            for(Actor a : getGrid().getNeighbors(getLocation()))
                a.setDirection(a.getDirection() + Location.RIGHT);
            
            setColor(Color.RED);
        }
        else
            setColor(Color.GREEN);
    }
}

2 thoughts on “Director free response answer

  1. Reply Henry May 10,2014 11:21 am

    In the else will points be taken off if I put super()?

    • Reply Brandon Horn May 10,2014 11:33 am

      Rock has a constructor that takes a Color object as a parameter. In the Director constructor super(Color.RED) has the same effect as setColor(Color.RED).

Leave a Reply