Question: Write a program that prompts the user for N random rectangles, create an array of N rectangles and print them. Do the following: Write a
Write a program that prompts the user for N random rectangles, create an array of N rectangles and print them.
Do the following:
Write a Rectangle class in a file named Rectangle.java
Add private instance variables height of type int to the Rectangle class
Add private instance variables width of type int to the Rectangle class
Add a empty constructor that initializes the rectangle's height and width to the value
Add a parameterized constructor that initialize the rectangle's height and width with the parameters' values.
Add a method getHeight that returns the height of the the rectangle.
Add a method setHeightint height that updates the instance variable height.
Add a method getWidth that returns the width of the the rectangle.
Add a method setWidthint width that updates the instance variable width.
Add a method getArea that returns the area of the rectangle.
Override the toString method to returns the string representation of the rectangle object. For example, if the rectangle has a height of and a width of then returned string is "Recth w
Create a method in Main class called randRectint n returns an array of n random rectangles. The width and height are generated randomly between and
In the main method, prompts for the number of rectangles. Then use the method randRectint n to generate the random rectangles. Then print each rectangles and its area as shown in the sample run.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
