Question: JAVA ONLY Exercise 1 Write a program that has a class Rectangle. The Rectangle has the following attributes length and width. The class should have

JAVA ONLY

Exercise 1

Write a program that has a class Rectangle. The Rectangle has the following attributes length and width. The class should have 3 constructors:

1 constructor that takes no parameters, length and width should be initialized with default values 3.0 and 5.0

1 constructor that takes length and with parameters as ints

1 constructor that takes length and with parameters as doubles

Setters and getters for width and length

Methods to calculate area and perimeter

Write a driver class that creates 2 objects of this class and calls their methods.

Exercise 2

Write a class called AdvancedRectangle. This class should be a subclass of Rectangle and also have an x and a y coordinate and should have a method calcCorners.

The constructor for advanced rectangle should take in x, y, length, and width and call the appropriate methods in the superclass.

calcCorners should calculate all 4 corners and the center of the rectangle and print their x and y coordinates on the screen. We assume the x and y coordinates in the constructor are of the upper right corner.

Write a driver class that creates 2 objects of this class and calls their methods.

Please comment for exercise 2.

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!