This is a homework I am having trouble on...We were given the base class by our professor and instructed to only worry about a circle and rectangle.
"In your derived classes, only implement draw and erase – not center. A rectangle needs length, height and position (x,y). A circle needs a radius and position. You are not going to actually draw anything – erase and draw should just write out that you are in them. Add all necessary additional constructors, variables and methods in the derived classes. Call super to get the base class constructor.
Write a
test program to test your classes. Your test program must store your objects polymorphically in a Figure array and call center from each element. Your code should look like this for the polymorphic section:
Notice that we can store any derived type in a base class array! This means that no matter how many shapes we have, refreshing is simply:
Here is sample output given by my professor...
Creating a rectangle.
R1 position (4,25) height = 5,width = 10
Creating a circle.
C1 position (5,5) radius = 44
Polymorphic Output:
In Figure, calling erase, draw
In Circle - doing erase
In Circle - doing draw
In Figure, calling erase, draw
In Rectangle - doing erase
In Rectangle - doing draw"
So far, my code gives me 2 compiler errors...
--------------------Configuration: <Default>--------------------
F:\Object Java\Rectangle.java:10: error: Rectangle is not abstract and does not override abstract method erase() in Figure
public class Rectangle extends Figure{
^
F:\Object Java\Circle.java:10: error: Circle is not abstract and does not override abstract method erase() in Figure
public class Circle extends Figure{
^
2 errors
Additionally, I am stuck on the idea of "Notice that we can store any derived type in a base class array! This means that no matter how many shapes we have, refreshing is simply: for(int i=0 ; i < num; i++) shapes[i].draw();.
I am also having trouble deciphering how to obtain the same output given by my professor.
Could anyone point me in the right direction or help me with some pseudo code so I can figure this out?