8A
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:
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 into your Bluej project.
For the draft, draw one random square in green using the predefined color from the Color class.
8B
There is no start file this time. You create a class called PracticeWithArrayLists with a main method In the main method, do the following
Add "tiger", "lion", "elephant", "kangaroo" in that order.Add "giraffe" at position 1set methodset method.Note: You must use an ArrayList and its methods. Do not fake it by just printing the correct strings. You will know how to use these methods in a situation where the output can not be faked.
Note: There is a version of remove method that will remove a specific object. Use that. Here is the code to remove target from the ArrayList called stuff
stuff.remove(target);
Note: To print an ArrayList, use its toString method like this
System.out.println(stuff);
8C
Finish the class Rectangles. It contains methods that manipulate an ArrayList of Rectangles
Rectangles has an instance variable ArrayList<Rectangle> Call the instance variable list. It has a constructor that takes no parameters but initializes the instance variable to an empty ArrayList
It has methods
public void add(Rectangle r) adds this Rectangle to the ArrayList of Rectanglespublic void swap(int index1, int index2) - swaps the element at index1 with the element at index2. If either index is out of bounds, do not changing anything.public Rectangle largest() gets the Rectangle with the largest area. If more than one Rectangle has the same areas, return the first. If the Rectangles object is empty, return nullpublic String toString() gets a string representation of the ArrayList - provided. (This is why the instance variable must be called list.)You will need to import the Udacity graphics package in order to use Rectangle
Provide Javadoc
Note that if you do not implement the methods in order, you may not get the expected results until all the methods are implemented
For the draft, implement the constructor and the add method