Question
NoRectangles (Int, Should Be Static. This Is A Counter Of The Number Of Rectangle Objects). 2- Write The Full-Argument Constructor, The No-Argument Constructor And The
1- Write a class Rectangle that has the following private attributes/fields:
name (String, should be final)
side2 (double) side1 (double)
side3 (double)
side3 (double)
noRectangles (int, should be static. This is a counter of the number of Rectangle objects).
2- Write the full-argument constructor, the no-argument constructor and the copy-constructor.
Note 1: the no-argument constructor and the copy-constructor need to call the full-argument constructor. The no-argument constructor sets name to InternalNameX, where X is the value of noRectangles, and it sets the sides to 1.0.
Note 2: validate the input in the full-argument constructor such that if the name is null it sets the attribute name to InternalNameX, where X is the value of noRectangles, and if the sides are not stricktly positive, it sets them to 1.0. It also must check the the values of the sides constitute a rectangle (side1 equals sides3 and side2 equals side4). If not, an IllegalArgumentException is generated.
3- Write the the getters and setters of all the attributes.
Note 3: validate the input in the setters according to Note 1.
4- Assuming the values of the sides constitute lengths in meter, overload two methods computeArea and computePerimeter (the return type of both is double) as follows:
If they take no argument they compute the area and the perimter in meter.
If they take one argument, then they check if the argument is cm (case insensitive) they return the area and the perimeter in centimeter, and if the argument is inch (case insensitive) they return the area and perimeter in inch. If the argument is none of these values, they throw an IllegalArgumentException.
Note 4: to convert from meter to inch multiply by 39.37.
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