Exercise 1:
The target of this exercise is to modify the classes
CircularT.java, LinealT.java,
SpiralT.java and LissajousT.java developed in the
last laboratory session in order to use the code inheritance facillity.
All these classes have exactly some code in common: the constant
npoints and the method Draw.
This code can be moved to a parent class, removing it from all the trajectory
classes. So, it is written only one time in the parent class
instead of writting it in all the files.
Remember that it is also necessary that all the trajectory classes
extend the parent class in order to inherit the common code.
However, as Draw uses the X and Y methods, they must also be
declared in the parent class as abstract methods. Otherwise, when compiling the parent class,
we will get a compilation error because there are references to two unknown methods,
X and Y.
Note that the parent class must be abstract because X and Y are abstracts.
Make these modifications:
- Write a abstract class, called Trajectory.java,
which implements the
constant npoints and the method Draw,
and define the abstract methods
X and Y.
- Remove npoints and the method Draw from all the trajectory classes.
- Make all the trajectory classes to extend the Trajectory class.
- Don't forget that Trajectory must implement the DisplayDrawable interface.
- Compile and test the new version of the classes. The test program is the same developed in
the last session laboratory: TestP.java
Exercise 2:
Apply the same modifications of the exercise 1 to the classes developed in the exercise 2
of the last session laboratory, i.e. the figure classes.
That is:
- Create an abstract class, called Figure, which contains the common code,
the necessary abstract methods, and that must implement DisaplyDrawable.
- Make all the developed figures to derive from figure.
- Include some figures in the test program, as well as the already included trajectories.
- Execute this new version.