2. To Do: Write a Java program that given the dimensions of a rectangle, and the number of random rectangles to generate, calculates the number of randomly generated rectangles with no-overlap with the given rectangle. Your program should ask the user to enter the number of random rectangles to generate as well as the dimensions of the given rectangle. The program should display a table which includes information about each randomly generated rectangle and the number of contained corners in the given rectangle. Finally, it should indicate the number of randomly generated rectangles with no-overlap. See the sample runs. 3. Additional requirements: 1. Number of generated rectangles should be greater than zero. 2. The position of the upper left corner of the given rectangle is (0, 0) and its dimensions should range between 10 and 100. 3. The upper left corner coordinates of each random rectangle are generated randomly to be less than 100 and greater than -100. Besides, its generated random dimensions should range between 30 and 50. 4. Two rectangle objects are constructed only once. Then just update the location and the dimensions for each generated rectangle using Rectangle API methods. 5. Use the Point and Rectangle API (java.awt) methods whenever is applicable. 6. Stop running the program if the input data type is incorrect. However, keep reading if the user enters invalid input range 4. Hints: Browse the API Documentation to see all the features of the following classes: Point, Rectangle, String. 5. Sample runs ➤ Sample 1: Please enter the width and the height of the given rectangle: 50 50 Please enter how many rectangles you would like to generate: -4 Error: Enter integer value> 0... Try Again Please enter how many rectangles you would like to generate: 3 **** * Rect# * R(x, w, h) * contained corners 532, 35) *(-5, -7, * (-100, 20, 35, 30) (-100, -100, 31, 34 ) Number of no-overlap with the given rectangle (0, 0, 50, 50) 2 * 1 *2 *3 y, 4 0 0 Sample 2: Please enter the width and the height of the given rectangles: abc. Error: It is not integer value... Exit

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter8: Advanced Data Handling Concepts
Section: Chapter Questions
Problem 3GZ
icon
Related questions
Question
An axis-aligned rectangle can be represented by the position (x, y) of its upper left corner and its dimensions
(width and height). This can be illustrated in a Windows coordinate system as follows:
Height
▼
Width
X
Figure 1: axis-aligned rectangle
Figure 2 shows four types of overlap between two axis-aligned rectangles. These types differ by the number of
corners included in one of the rectangles. The black rectangle contains all the 4 corners of the red rectangle, two
corners of the blue rectangle and exactly one corner of the green rectangle, while it contains no corner of the
orange rectangle.
Figure 2: overlap with black rectangle
Transcribed Image Text:An axis-aligned rectangle can be represented by the position (x, y) of its upper left corner and its dimensions (width and height). This can be illustrated in a Windows coordinate system as follows: Height ▼ Width X Figure 1: axis-aligned rectangle Figure 2 shows four types of overlap between two axis-aligned rectangles. These types differ by the number of corners included in one of the rectangles. The black rectangle contains all the 4 corners of the red rectangle, two corners of the blue rectangle and exactly one corner of the green rectangle, while it contains no corner of the orange rectangle. Figure 2: overlap with black rectangle
2. To Do:
Write a Java program that given the dimensions of a rectangle, and the number of random rectangles to generate,
calculates the number of randomly generated rectangles with no-overlap with the given rectangle. Your program
should ask the user to enter the number of random rectangles to generate as well as the dimensions of the given
rectangle. The program should display a table which includes information about each randomly generated rectangle
and the number of contained corners in the given rectangle. Finally, it should indicate the number of randomly
generated rectangles with no-overlap. See the sample runs.
3. Additional requirements:
1. Number of generated rectangles should be greater than zero.
2.
The position of the upper left corner of the given rectangle is (0, 0) and its dimensions should range
between 10 and 100.
3. The upper left corner coordinates of each random rectangle are generated randomly to be less than 100
and greater than -100. Besides, its generated random dimensions should range between 30 and 50.
4.
Two rectangle objects are constructed only once. Then just update the location and the dimensions for
each generated rectangle using Rectangle API methods.
5. Use the Point and Rectangle API (java.awt) methods whenever is applicable.
6.
Stop running the program if the input data type is incorrect. However, keep reading if the user enters
invalid input range
4. Hints:
Browse the API Documentation to see all the features of the following classes: Point, Rectangle, String.
5. Sample runs
➤ Sample 1:
Please enter the width and the height of the given rectangle: 50 50
Please enter how many rectangles you would like to generate: -4
Error: Enter integer value> 0... Try Again
Please enter how many rectangles you would like to generate: 3
****
* Rect# * R(x,
w, h) * contained corners
532, 35)
*(-5, -7,
* (-100,
20,
35, 30)
(-100, -100,
31, 34 )
Number of no-overlap with the given rectangle (0, 0, 50, 50) 2
* 1
*2
*3
y,
4
0
0
Sample 2:
Please enter the width and the height of the given rectangles: abc.
Error: It is not integer value... Exit
Transcribed Image Text:2. To Do: Write a Java program that given the dimensions of a rectangle, and the number of random rectangles to generate, calculates the number of randomly generated rectangles with no-overlap with the given rectangle. Your program should ask the user to enter the number of random rectangles to generate as well as the dimensions of the given rectangle. The program should display a table which includes information about each randomly generated rectangle and the number of contained corners in the given rectangle. Finally, it should indicate the number of randomly generated rectangles with no-overlap. See the sample runs. 3. Additional requirements: 1. Number of generated rectangles should be greater than zero. 2. The position of the upper left corner of the given rectangle is (0, 0) and its dimensions should range between 10 and 100. 3. The upper left corner coordinates of each random rectangle are generated randomly to be less than 100 and greater than -100. Besides, its generated random dimensions should range between 30 and 50. 4. Two rectangle objects are constructed only once. Then just update the location and the dimensions for each generated rectangle using Rectangle API methods. 5. Use the Point and Rectangle API (java.awt) methods whenever is applicable. 6. Stop running the program if the input data type is incorrect. However, keep reading if the user enters invalid input range 4. Hints: Browse the API Documentation to see all the features of the following classes: Point, Rectangle, String. 5. Sample runs ➤ Sample 1: Please enter the width and the height of the given rectangle: 50 50 Please enter how many rectangles you would like to generate: -4 Error: Enter integer value> 0... Try Again Please enter how many rectangles you would like to generate: 3 **** * Rect# * R(x, w, h) * contained corners 532, 35) *(-5, -7, * (-100, 20, 35, 30) (-100, -100, 31, 34 ) Number of no-overlap with the given rectangle (0, 0, 50, 50) 2 * 1 *2 *3 y, 4 0 0 Sample 2: Please enter the width and the height of the given rectangles: abc. Error: It is not integer value... Exit
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning