Define two derived classes of the abstract class ShapeBase. Your two classes wil
ID: 3535618 • Letter: D
Question
Define two derived classes of the abstract class ShapeBase. Your two classes will be called RightArrow and LeftArrow. The size of the arrow is determined by two numbers, one for the lenght of the "tail" and one for the width of the arrowhead. (The width is the lenght of the vertical base.) The width of the arrowhead cannot be an even number, so your constructors and mutator methods should check to make sure that is always odd. Write a test program for each class that tests all the methods in the class. you can assume that the width of the base of the arrowhead in at least 3.
an example of an arrow
*
********** *
*
The ShapeBase Class
public abstract class ShapeBase implements ShapeInterface
{
private int offset;
public abstract void drawHere ();
public ShapeBase ()
{
offset = 0;
}
public ShapeBase (int theOffset)
{
offset = theOffset;
}
public void setOffset (int newOffset)
{
offset = newOffset;
}
public int getOffset ()
{
return offset;
}
public void drawAt (int lineNumber)
{
for (int count = 0 ; count < lineNumber; count++)
System.out.println ();
drawHere ();
}
}
public interface ShapeInterface
{
public void setOffset (int newOffset);
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.