Shape Classes Design classes Square, RightTriangle , and Triangle that encapsulate three geometric shapes. Each class should implement a method void draw (int x, int y) that “draws" a square, a right...


Shape Classes<br>Design classes Square, RightTriangle , and Triangle that encapsulate three geometric shapes. Each class should<br>implement a method<br>void draw (int x, int y)<br>that “draws

Extracted text: Shape Classes Design classes Square, RightTriangle , and Triangle that encapsulate three geometric shapes. Each class should implement a method void draw (int x, int y) that “draws" a square, a right triangle, or an equilateral triangle (a triangle with three equal sides), respectively. See Figure 2. The parameters x and y specify the relative position of the figure: y lines down and x spaces acro from the current position of the screen cursor. The instance variables of each class are: int rows , the number of rows that comprise the figure, and char character , the keyboard character used for drawing the figure. Each shape of Figure 2 consists of five rows. The drawing characters are *** for the square, %' for the right triangle, and #' for the equilateral triangle. Shape (abstract) int rows char character Shape() Shape(int x, char c) int get rows() char getCharacter() void setRows(int x) void setCharacter(int x) void draw(int x, int y) (abstract) Square() Square(int x, char ch) void draw(int x, int y) RightTriangle() RightTriangle(int x, char ch) void draw(int x, int y) Triangle() Triangle(int x, char ch) void draw(int x, int y) Square RightTriangle Triangle Figure 2: Shape Hierarchy Requirement: a. Provide an implementation of the classes. b. Create a TestShape class that will allow the Shape class to polymorph to the subclasses. Call the constructor method and draw the corresponding shape by calling the draw method.

Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here