Consider the following TestBug class declaration. (
Appendix )
public class TestBug extends Bug
{
public void act()
{
if (canMove())
{
move();
if (canMove())
move();
}
else
{
setDirection(getDirection() + Location.HALF_CIRCLE);
}
}
}
The following code segment will produce a grid that has a Rock object and a TestBug object placed as shown.
Grid<Actor> g = new BoundedGrid<Actor>(5, 5);
Rock r = new Rock();
r.putSelfInGrid(g, new Location(2, 1));
Bug t = new TestBug();
t.putSelfInGrid(g, new Location(3, 2));
Which of the following best describes what the TestBug object t does as a result of calling t.act() ?
(A) Moves forward two locations and remains facing current direction
(B) Moves forward two locations and turns 180 degrees
(C) Moves forward one location and remains facing current direction
(D) Moves forward one location and turns 180 degrees
(E) Stays in the same location and turns 180 degrees