Answered step by step
Verified Expert Solution
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 argument for a side that calls Rectangles constructor with 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 x the width. Write constructors for it and test it out.
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