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 across 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 constructo method and draw the corresponding shape by calling the draw method.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
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.
Transcribed Image 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY