Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!