Question: Need help writing a program in Java! Design a Rectangle class that has the following data fields: (1) Define all data members, width and height,

Need help writing a program in Java!

Design a Rectangle class that has the following data fields:

(1) Define all data members, width and height, as private;

(2) Redefine constructors so as to avoid writing duplicated code by using this

(3) Add setter methods through which to change width and height

(4) In test class, define an array of Rectangle type, create some Rectangle objects and save them in array;

(5) Define a method that has an array of Rectangle as input parameter. The method will calculate the total area of all Rectangle objects in array; return this total value from the method. Display result in main().

width (double) height (double) Define the following methods in the class: 2 constructors: the first constructor will initialize width and height to default values of 1.0; the second constructor will use input arguments to initialize width and height; A method to return width of a Rectangle object; A method to return height of a Rectangle object; A method to return area of a Rectangle object; Test: create 3 Rectangle objects; display width, height of these rectangle objects; calculate the total area of all these 3 rectangle objects

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!