Please complete this homework before next class.
Basic Review Problems
1. Create an integer called "x" that is equal to a random integer.
Use a while loop to print every number between 0 and x.
2. Create two Strings, x and y. x should equal "Cat" and y should equal "Dog".
Add the Strings together and print them.
3. Create an integer variable called "x" that is equal to a random number.
If x is less than 100, print "LOW". If x is greater than or equal to 100
print "HIGH".
Array Review Problems
1. Create an array of Strings of size 50. Every String in the array should be
the String "Moose".
2. Write code to print every String in the array. Use a while loop for this.
3. Create an array of 50 integers. Fill the array with all of the numbers
between 0 and 50.
4. Create an integer called "sum". Add all of the numbers in the previous array
to sum, and then print sum.
Function Review Prolems
1. Create a function call printN() that takes in an integer "n".
The function should print every number between 0 and n.
EX : If we give the function the following input :
printN(5);It should print :
0 1 2 3 4 5
2. Create a function called "createArray()" that takes in one integer parameter, "n".
The function should return an integer array of size "n". Every element in
the array should be equal to a random integer.
3. Create a function called "printSometimes()". The function should take in
a String "x" as a parameter. It should print "x" ONLY if x.length() is
greater than 4.
4. Create a function called "printArray()" that takes in an array of integers as a parameter.
It should print every integer in the array.
If you're successfull, you could use this code to test your function :
void setup() { int[] array = new int[] { 1, 6, 87, 2 }; printArray(array); }
Class Review Problems
1. Create a class called Rectangle that represents a Rectangle.
Rectangles have an x, y, width and height.
2. Next, write code to create a single rectangle and draw that rectangle onto the screen.
3. Modify your rectangle class so that it has a random color.
This means that the Rectangle class will need an r, g, and b.
4. Create a method in your Rectangle class called "randomize()".
This method should set the Rectangle's x, y, width, height, and color
to be random values.
This code could be used to test your method :
void draw() { Rectangle r = new Rectangle(); r.randomize(); fill(r.r, r.g, r.b); rect(r.x, r.y, r.width, r.height); }
5. This one is hard. Create an array of Rectangles in the setup function.
Fill the array with Rectangles. Call the randomize() method on each Rectangle.
Draw every Rectangle in the array to the screen in the draw() function.