Homework 4


Problem Set A

Create a function called checkAge. The function should take in an
integer called 'age'. It should return true only if age is greater than 21.

Write a program that multiplies all of the numbers between 1 and 10 together.

It should use a for loop to do this. It should print the result.

Create a function called output. It should take in an integer i. It should print
out the integer i using println. It does not return anything.
Next, use a for loop in the setup function to call that function with all
of the integers between -5 and 10.

Problem Set B

First create the setup and draw functions.

Next, create the following global variables :
an integer x (starts at 300)
an integer y (starts at 300)
an integer speedX (starts at 1)
an integer speedY (starts at 1)

Next, in your setup function set the screen size to 800, 600

In the draw function, add a function call to draw the background.

After the background(...) call, draw an ellipse at x, y.

After you draw the ellipse, make x increase by speedX and y
increase by speedY every time draw runs.

Now, add in code into the draw function so that if the circle hits
the bottom of the screen, the speedY becomes negative.

Add in more logic so that if the ellipse hits any edge it bounces the other way.

[Extra Credit] If you're feeling like a challenge, change the program
to use arrays instead of just integers and fill the screen
with moving balls. If you are able to do this, I'll show your code off to the class.