Define two derived classes of the abstract class ShapeBase below. Your two class
ID: 3535597 • Letter: D
Question
Define two derived classes of the abstract class ShapeBase below. Your two classes will be called RightArrow and LeftArrow. These classes will draw arrows that point right and left, respectively. The size of the arrow is determined by two numbers, one for the length of the tail and one for the width of the arrowhead. These values are 16 and 7 in the above display. The width of the arrowhead cannot be an even number, so your constructors and mutator methods should check to make sure that it is always odd. Write a test program for each class that tests all methods in the class. You can assume the width of the base of the arrowhead is at least 3.
*
* *
* *
**************** *
* *
* *
*
// Base class (ShapeBase)
public abstract class ShapeBase implements ShapeInterface{
protected int offset;
// I made offset protected so that the subclasses can refrence it directly
public void setOffset(int newOffset)
{
offset = newOffset;
}
public int getOffset()
{
return offset;
}
public abstract void drawHere();
public void drawAt(int lineNumber)
{
for(int i=0; i<lineNumber; i++)
System.out.println();
drawHere();
}
}
// Shape Interface
public interface ShapeInterface{
public void setOffset(int offset);
public int getOffset();
public void drawAt(int lineNumber);
public void drawHere();
}
Explanation / Answer
I am not giving you the code for drawing leftarrow and rightarrow but I m giving you the code for the interface of shapebase, the shapebase and the arrowDriver program. To make these arrows, biggest point is the coordinates, the offset. So I did this for drawing, and it worked for me. I have stored the logic here.
Kindly dont forget to rate if this helps you
Cheers!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.