Define a class called Diamond that is derived from either the class ShapeBasics (Listing 8.12) or the

Question:

Define a class called Diamond that is derived from either the class ShapeBasics (Listing 8.12) or the abstract class ShapeBase (Listing 8.19). A diamond has the same sort of top half as a Triangle object, and its bottom half is an inverted version of its top half. Define a utility class having public static methods, such as the method skipSpaces and other methods that draw horizontal lines, big V’s, and inverted big V’s. Recall that Self-Test Question 31 asked you to describe one method in this class.


Listing 8.12

/**
Class for drawing simple shapes on the screen using keyboard characters. This class will draw an asterisk on the screen as a test. It is not intended to create a "real" shape, but rather to be used as a base class for other classes of shapes.
*/
public class ShapeBasics implements ShapeInterface
{
private int offset;
public ShapeBasics()
{
offset = 0;
}
public ShapeBasics(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 void drawHere()
{
for (int count = 0; count < offset; count++)
System.out.print(' ');
System.out.println('*');
}
}

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: