Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package shapes; public class Shape { private int height = 0; private int width = 0; private char pattern = '*'; /** * Default constructor
package shapes; public class Shape { private int height = 0; private int width = 0; private char pattern = '*'; /** * Default constructor **/ public Shape() { this.height = 0; this.width = 0; } /** * Constructor * @param h height of a Shape * @param w width of a Shape **/ public Shape(int h, int w) { this.height = h; this.width = w; } /** * Setter for the height * @param h the height **/ public void setHeight(int h) { this.height = h; } /** * Setter for the width * @param w the width **/ public void setWidth(int w) { this.width = w; } /** * Setter for the pattern * @param c the char to use **/ public void setPattern(char c) { this.pattern = c; } /** * Getter for height * @return int: the height **/ public int getHeight() { return this.height; } /** * Getter for the width * @return int: the width **/ public int getWidth() { return this.width; } /** * Getter for the pattern * @return the char to use when drawing the Shape **/ public char getPattern() { return this.pattern; } /** * Overloading the default toString method * @return String: the class name, the Shape's height and width **/ public String toString() { return getClass() + " => Height: " + getHeight() + " Width: " + getWidth(); } }
Using the Shape.java file available on moodle, extend the Shape class into the following classes: Rectangle: Define the draw() method to print a rectangle of height by width of the char stored in pattern Square: Override both setWidth and setHeight so that both values are always the same. Write the appropriate draw) method Triangle: Add a variable angle which will be set to 90 (for simplicity's sake). Override toString() to print the angle as well as the rest of the information Implement the draw() method
Step 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