Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this challenge, you are giving a class called Rectangle that has two instance variables, length and width, a constructor that initializes them, and a

In this challenge, you are giving a class called Rectangle that has two instance variables, length and width, a constructor that initializes them, and a method called draw that uses nested loops to draw a length x width rectangle of stars. Try it out below.
You will write a new class called Square that inherits from Rectangle. Is a square a rectangle? Yes! A square is a rectangle where the length and width are equal. Square will inherit length, width, and the draw method. You will write Square constructors that will call the Rectangle constructors.
Make the class Square below inherit from Rectangle
Add a Square constructor with 1 argument for a side that calls Rectangles constructor with 2 arguments using super.
Uncomment the objects in the main method to test drawing the squares.
Add an area method to Rectangle that computes the area of the rectangle. Does it work for Squares too? Test it.
Add another subclass called LongRectangle which inherits from Rectangle but has the additional condition that the length is always 2 x the width. Write constructors for it and test it out.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Shouhong Wang, Hai Wang

1st Edition

1612330150, 978-1612330150

More Books

Students also viewed these Databases questions