You will need to import the graphics package into your BlueJ project. Write a Java application RandomRectangles which prompt for a positive integer then draws that number of random rectangles. If the input is not a positive integer, the program will display a message and prompt for input again until a positive integer is entered. The program also finds the rectangle with the smallest area and display the number of the rectangles and the smallest area. Draw the squares in red. After you have drawn all the rectangles, fill the rectangle with the smallest area with yellow. Use the predefined colors from the Color class. If more than one rectangle has the smallest area, use the last one with that area as the smallest. You should declare and use the following constants: public static final int MAX_X = 100; public static final int MAX_Y = 500; public static final int MIN_WIDTH = 30; public static final int MAX_WIDTH = 100; public static final int MIN_HEIGHT = 20; public static final int MAX_HEIGHT = 80; public static final int GENERATOR_SEED = 202210; All rectangles have random widths and heights at random locations. The (x, y) coordinates are for the upper-left corner of the rectangle. Make the x coordinate a random number between 0 (inclusive) and 100 (exclusive), the y coordinate a random number between 0 (inclusive) and 500 (exclusive). Make the width a random value between 30 (inclusive) and 100 (exclusive), the height a random value between 20 (inclusive) and 80 (exclusive). You must use the given seed GENERATOR_SEED, 202210, to generate the random numbers. For each rectangle, generate the random values in this order: x coordinate, y coordinate, width, and height. All values are integers. You must use one for loop to draw the rectangles and find the smallest one, and not store the rectangles in an array list or an array. You must use one Scanner object and call Scanner methods to process input. You cannot use try- catch statement or call any parse method. The Codecheck server will run your program three times using different input sets and the expected output is attached at the end of t

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question
You will need to import the graphics package into your BlueJ project. Write a Java application RandomRectangles which prompt for a positive integer then draws that number of random rectangles. If the input is not a positive integer, the program will display a message and prompt for input again until a positive integer is entered. The program also finds the rectangle with the smallest area and display the number of the rectangles and the smallest area. Draw the squares in red. After you have drawn all the rectangles, fill the rectangle with the smallest area with yellow. Use the predefined colors from the Color class. If more than one rectangle has the smallest area, use the last one with that area as the smallest. You should declare and use the following constants: public static final int MAX_X = 100; public static final int MAX_Y = 500; public static final int MIN_WIDTH = 30; public static final int MAX_WIDTH = 100; public static final int MIN_HEIGHT = 20; public static final int MAX_HEIGHT = 80; public static final int GENERATOR_SEED = 202210; All rectangles have random widths and heights at random locations. The (x, y) coordinates are for the upper-left corner of the rectangle. Make the x coordinate a random number between 0 (inclusive) and 100 (exclusive), the y coordinate a random number between 0 (inclusive) and 500 (exclusive). Make the width a random value between 30 (inclusive) and 100 (exclusive), the height a random value between 20 (inclusive) and 80 (exclusive). You must use the given seed GENERATOR_SEED, 202210, to generate the random numbers. For each rectangle, generate the random values in this order: x coordinate, y coordinate, width, and height. All values are integers. You must use one for loop to draw the rectangles and find the smallest one, and not store the rectangles in an array list or an array. You must use one Scanner object and call Scanner methods to process input. You cannot use try- catch statement or call any parse method. The Codecheck server will run your program three times using different input sets and the expected output is attached at the end of the document.
Testing RandomRectangles.java
Test 1
Enter a positive integer for the number of rectangles: Java
Not an integer: "Java".
Enter a positive integer for the number of rectangles: Programming
Not an integer: "Programming".
Enter a positive integer for the number of rectangles: Q
Not an integer: "Q".
Enter a positive integer for the number of rectangles: 5
The number of rectangles: 5.
The min area: 1755.
Image:
pass
Test 2
Not positive: -1.
Enter a positive integer for the number of rectangles: 0
Not positive: 0.
Enter a positive integer for the number of rectangles: 2.5
Not an integer: "2.5".
Enter a positive integer for the number of rectangles: 25
The number of rectangles: 25.
The min area: 1680.
Image:
Transcribed Image Text:Testing RandomRectangles.java Test 1 Enter a positive integer for the number of rectangles: Java Not an integer: "Java". Enter a positive integer for the number of rectangles: Programming Not an integer: "Programming". Enter a positive integer for the number of rectangles: Q Not an integer: "Q". Enter a positive integer for the number of rectangles: 5 The number of rectangles: 5. The min area: 1755. Image: pass Test 2 Not positive: -1. Enter a positive integer for the number of rectangles: 0 Not positive: 0. Enter a positive integer for the number of rectangles: 2.5 Not an integer: "2.5". Enter a positive integer for the number of rectangles: 25 The number of rectangles: 25. The min area: 1680. Image:
pass
Test 3
Enter a positive integer for the number of rectangles: 50
The number of rectangles: 50.
The min area: 660.
Image:
pass
Transcribed Image Text:pass Test 3 Enter a positive integer for the number of rectangles: 50 The number of rectangles: 50. The min area: 660. Image: pass
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
JQuery and Javascript
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT