Activity 1.4 - Robot world - inheritance, overriding and overloading
Topic
This exercise allows you to test all the various robot classes that inherit
from the simple Robot class, discussed in the course
text. It also displays the robot movement graphically on a grid.
Materials
In addition to the Solution document, the project for this exercise contains
six classes:
- Robot, which is complete;
- MagicRobot, which inherits from Robot, and is also complete;
- SpeedRobot, which inherits from Robot, and is incomplete;
- VariableSpeedRobot, which inherits from SpeedRobot, and is
also incomplete;
- TestRobot, which is complete;
- Grid, which is responsible for the graphical display of
the grid containing the various robots.
This represents the most complex set of classes we have seen so far. Realistic
large commercial systems may contain hundreds or even thousands of classes.
Task
In the test class TestRobot,
we have provided code to create the various robot objects and to invoke some of
their methods. The program should compile and run already but some kinds of
robots will not behave properly. You are to complete the classes SpeedRobot and VariableSpeedRobot.
Instructions
- Complete the code for the four methods of the SpeedRobot class, moveNorth, moveSouth, moveEast and moveWest, which
override the corresponding methods in the Robot class.
- Complete the code for the four methods of the VariableSpeedRobot class, moveNorth, moveSouth, moveEast and moveWest, which
overload the corresponding methods in the SpeedRobot
class.
- Build and run the project and check that both
the text output and graphical output are as you would expect, given the
statements in the main method of the TestRobot class.