Strategy 1
Skills:
- Make an instance variable.
- Define an interface.
- Implement an interface.
- Write a constructor given some information.
Questions:
-
The class
MLM
is aStrategy
that moves forward, puts down a beeper, turns left, and moves forward again. Write the classMLM
. -
Write the class
XBot
, which is a class of robot that only moves horizontally.- Starts at street=n, avenue=3 facing East
turnLeft
really turns the robot to face in the opposite direction of the original direction
-
Create a new interface
NamedStrategy
which adds aString stratName()
method to the abilities of aStrategy
. ThestratName()
method should return the strategy’s name. -
Make a class
LaySpeak
which implementsNamedStrategy
. ThedoIt
method both puts down two beepers and prints out the name of the strategy.System.out.println(name of strategy);
This kind of strategy should learn its name when it is constructed.