Question: JAVA: Complete the application RandomSquares which uses a loop to draw 25 squares with random length sides at random locations. Make the x coordinate a

JAVA:

Complete the application RandomSquares which uses a loop to draw 25 squares with random length sides at random locations. Make the x coordinate a random number between 0 (inclusive) and 200 (exclusive), Make the y coordinate a random number between 0 and 300 (exclusive). This x,y is the upper left hand corner of the rectangle (square). Make the length of the sides a random value between 20 (inclusive) and 100 (exclusive). Declare and use constants for:

maximum x coordinate

maximum y coordinate

maximum length

minimum length

number of squares

Some constants are already defined for you. You do the rest

In the starter file, I have created a Random object for you with a seed. Be sure to use it. Because of the seed, the Random object will produce the same sequence of numbers every time the program is run so your drawing will always look the same (and will pass Codecheck). Do not change the seed.

Generate the random values in this order: x coordinate, y coordinate, length of the side.

You must use a loop. Do not have 25 lines of code each of which draws a square

Draw the squares in green. After you have drawn all the squares, fill the largest square with blue. Use the predefined colors from the Color class. If more than one square has the largest side, use the first one with that side as the largest. You will need to keep track of the largest as you go.

You will need to import Dr. Horstmann's graphics package(https://s3.amazonaws.com/udacity-hosted-downloads/graphics.zip) into your Bluej project.

Complete the following file:

RandomSquares.java

import java.util.Random; /** * Draws random squares */ public class RandomSquares { public static void main(String[] args) { final int MAX_X = 200; final int MAX_Y = 300; Random gen = new Random(987456789); } }

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 Databases Questions!