Implement a class Rectangle which represents a rectangle shape as described below: A. The Rectangle class has

Question:

Implement a class Rectangle which represents a rectangle shape as described below:
A. The Rectangle class has one private class constant DEFAULT_VALUE that should be initialized to 0.0 .
B. The Rectangle class has two private instance data members, side X and side Y, of type double.
C. The first constructor is a default constructor and calls the third constructor (described below) using the reserved word this to set instance data members to the default value.
D. The second constructor calls the third constructor (described below) using the reserved word this. It retrieves a Rectangle object as a formal parameter and copies sideX and sideY of the object to the new object.
E. The third constructor calls the setSides method (described below). Two formal parameters are used as the parameters for the setsides method.
F. The mutator methods, setSideX and setSideY, each has one formal parameter and stores them in the instance data member.
G. Another mutator method, setSides, has two formal parameters and stores them in the instance data members by using the setSideX and setSideY methods (described above).
H. The accessor methods, getSideX and getSideY, return the value of the appropriate instance data member.
I. A method named calcArea computes the area of a rectangle and returns the computed area.
Next, write a client program to test the Rectangle class defined above. This class should be named Rectangles and should contain the main method which performs the following tasks:
a. Declare three Rectangle objects.
b. Create three Rectang le objects using the three different constructors.
c. Output the contents of side X and side Y of the three objects.
d. Output the area of the third rectangle.
Here is some sample output:
image text in transcribed

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: