SE-0010 Introduction to Java
Lab 5: Random Color Spirographer

Outcomes

Assignment

This assignment requires you to make a fairly simple modification of your Spirographer program from Lab 4. In this lab, you'll add a switch statement inside the for() loop within the display() method so that the pen color you use to draw the plot randomly changes, resulting in a graph that might look something like this:

Within your display method, you should have a for() loop that iterates the value of t from 0 to 10000. In each iteration, a small piece of the curve is drawn by drawing to the x,y coordinates you calculate from the formula given in Lab 4. Within the for() loop, just before you call the drawTo() method, you need to insert some addtional statements that randomly change the pen color used to draw. To begin, insert the following statement:

int randomValue = (int) (Math.random()*10); // generate a random integer value between 0 and 10.

The Math.random() method actually generates random double (fractional) values between 0.0 and 1.0. In the statement above, these random fractions are multiplied by 10 to give values that range from 0.0 to 10.0. Then, the (int) cast converts the fractional values to integer values (0-10) that get assigned to the randomValue variable.

Following this random number generation, insert a switch statement that has 11 cases (0-10). For each case, set the pen color to a different value - the choice of pen color for each case is up to you.

You should finish this assignment within the lab period. Demonstrate the results to your instructor after completion.

Lab Submission (due no later than Sunday 11pm)

Submit your completed Java program via via WebCT (assignment "Lab 5: Random Color Spirograph").. For this program, your program will consist of a single .java file.

Be sure to keep a copy of your work, in case something gets lost.

Your grade will be based on the following criteria: