Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Just need help with TASK 2, Task 1 for reference! [Task 1] In this task, you will create a subclass called Rectangle which is derived

image text in transcribed

Just need help with TASK 2, Task 1 for reference!

[Task 1] In this task, you will create a subclass called Rectangle which is derived from the superclass Square. Study how the subclass Rectangle invokes the superclass' constructors (via super() and super(length)) and inherits the variables and methods from the superclass Square. You can reuse the Square class that you have created in the previous exercise. Make sure that you keep "Square.java" in the same directory. A partially complete (Skeleton) Rectangle.class code is shown below. public class Rectangle extends Square { // Save as "Rectangle.java" private double width; // private variable // Constructor with default color, length and width public Rectangle() { super(); // call superclass no-arg constructor Square () width = 1.0; ? constructor with default length, color but given width public Rectangle (double width) { //put your code here } // Constructor with default color, but given length, width public Rectangle (double length, double width) { //put your code here // A public method for retrieving the width public double getWidth() { //put your code here } 1/ A public method for computing the area of Rectangle public double getArea() { //put your code here } [Task 2] Write a test program (called TestRectangle) to test the Rectangle class created. The program should achieve the following tasks: Declare and allocate a new instance of Rectangle Rl with default color, length, and width Calculate and print the area of the Rectangle R1 Declare and allocate a new instance of Rectangle R2 specifying width, with default color and length Calculate and print the area of the Rectangle R2 Declare and allocate a new instance of Rectangle R3 specifying length and width, with default color Calculate and print the area of the Rectangle R3

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions