Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions