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...


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, sideX and


sideY, 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 Rectangle objects using the three different constructors.


c. Output the contents of sideX and sideY of the three objects.


d. Output the area of the third rectangle.


Here is some sample output:


rectangle1: sideX ¼ 0.0, sideY ¼ 0.0


rectangle2: sideX ¼ 3.0, sideY ¼ 4.0


rectangle3: sideX ¼ 3.0, sideY ¼ 4.0


rectangle3: area ¼ 12.0

May 26, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here