Question
USE THE FOLLOWING CODE public class OurTester { public static void main(String [] arg) { SolidRectangle shape1 = new SolidRectangle(); shape1.setOffset(10); shape1.set(7, 5); shape1.drawAt(5);}} --------------------------------------------------------------
USE THE FOLLOWING CODE
public class OurTester
{
public static void main(String [] arg)
{
SolidRectangle shape1 = new SolidRectangle();
shape1.setOffset(10);
shape1.set(7, 5);
shape1.drawAt(5);}}
--------------------------------------------------------------
public class Rectangle extends ShapeBasics implements RectangleInterface { private int height; private int width; public Rectangle( ) { super( ); height = 0; width = 0; } public Rectangle(int theOffset, int theHeight, int theWidth) { super(theOffset); height = theHeight; width = theWidth; } public void set(int newHeight, int newWidth) { height = newHeight; width = newWidth; } /** Draws the shape at the current line. */ public void drawHere( ) { drawHorizontalLine( ); drawSides( ); drawHorizontalLine( ); }
private void drawHorizontalLine( ) { skipSpaces(getOffset( )); for (int count = 0; count
-----------------------------------------------------------------------
public interface RectangleInterface extends ShapeInterface
{
Sets the rectangle's dimensions.
public void set(int newHeight, int newWidth);
}
----------------------------------------------------------
public class ShapeDemo
{
public static void main(String[] args)
{
RectangleInterface box = new Rectangle(5, 8, 4);
box.drawHere();
box.set(5, 5);
box.setOffset(10);
box.drawAt(2);}}
-------------------------------------------------
public class SolidRectangle extends Rectangle
{
String fillCh; //The character to fill rectangle with
public SolidRectangle()
{
super();
}
public SolidRectangle(int theOffset, int theHeight, int theWidth)
{
super(theOffset, theHeight,theWidth);
}}
-----------------------------------------------
Class for drawing triangles on the screen using keyboard
characters. A triangle points up. Its size is determined
by the length of its base, which must be an odd integer.
Inherits getOffset, setOffset, and drawAt from the class
ShapeBasics.
*/
public class Triangle extends ShapeBasics implements TriangleInterface
{
private int base;
public Triangle( )
{
super( );
base = 0;
}
public Triangle(int theOffset, int theBase)
{
super(theOffset);
base = theBase;
}
/** Precondition: newBase is odd. */
public void set(int newBase)
{
base = newBase;}
/**
Draws the shape at current line.
*/
public void drawHere( )
{
drawTop( );
drawBase( );}
-----------------------------------------------------------
/**
Interface for a triangle to be drawn on the screen.
*/
public interface TriangleInterface extends ShapeInterface
{
/**
Sets the triangle's base.
*/
public void set(int newBase);}
---------------------------------------------------------------------
/**
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;
}
/**
Draws the shape at lineNumber lines down
from the current line.
*/
public void drawAt(int lineNumber)
{
for (int count = 0; count
--------------------------------------------------------------
System.out.println( );
drawHere( );
}
/**
Draws the shape at the current line.
*/
public void drawHere()
{
for (int count = 0; count
System.out.print(' ');
System.out.println('*');}}
------------------------------------------------
/**
Interface for simple shapes drawn on
the screen using keyboard characters.
*/
public interface ShapeInterface
{
/**
Sets the offset for the drawing.
*/
public void setOffset(int newOffset);
/**
Returns the offset for the drawing.
*/
public int getOffset();
/**
Draws the shape at lineNumber lines down
from the current line.
*/
public void drawAt(int lineNumber);
/**
Draws the shape at the current line.
*/
public void drawHere();
}
Drawing Shapes Exercise Complete the SolidRectangle class that we started developing in class. SolidRectangle should work just like Rectangle only it should allow a way for a character to be chosen to fill the rectangle with. For example if we create a 6x9 rectangle with "o" as the fill character it would produce a rectangle similar to the following: |oo00o00 l 0000ooo oooo000| If a "+" is chosen as the fill character it would produce: NOTE: Do not reinvent the wheel. As much as possible take advantage of the existing classes and Drawing Shapes Exercise Complete the SolidRectangle class that we started developing in class. SolidRectangle should work just like Rectangle only it should allow a way for a character to be chosen to fill the rectangle with. For example if we create a 6x9 rectangle with "o" as the fill character it would produce a rectangle similar to the following: |oo00o00 l 0000ooo oooo000| If a "+" is chosen as the fill character it would produce: NOTE: Do not reinvent the wheel. As much as possible take advantage of the existing classes andStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started