Strategy 2
-
Controller
is an interface with avoid doIt()
method. Write the interface. -
Write
DoubleDot
class implementing theController
interface that tells two robots to put a beeper and move.DoubleDot
itself is not a robot. TheDoubleDot
class has to find out whichUrRobot
s in its constructor.public static void demo() { UrRobot x = new UrRobot(3,1,Directions.East,5); UrRobot y = new UrRobot(5,1,Directions.South,2); DoubleDot c = new DoubleDot(x,y); c.doIt(); // x puts a beeper and moves to (3,2) // y puts a beeper and moves to (4,1) }
-
The
BC
class is a kind ofUrRobot
that uses a Controller. These robots always start at street=7, avenue=3, with 10 beepers. The constructor should take in the direction and a Controller.When you tell a
BC
robot to move, it moves and applies thedoIt()
method of the controller.