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 1.
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 setHeight(int height) that updates the instance variable height.
Add a method getWidth() that returns the width of the the rectangle.
Add a method setWidth(int 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 5 and a width of 3, then returned string is "Rect[h=5, w=3]"
Create a method in Main class called randRect(int n) returns an array of n random rectangles. The width and height are generated randomly between 1 and 10.
In the main method, prompts for the number of rectangles. Then use the method randRect(int 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 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 Programming Questions!