Lab 5 Post-Lab Assignment: Drawing Random Hats
Due Friday, October 7, 2005

Write a Hat class that creates a graphical hat object (a top hat formed by a rectangle and a line for the brim) with attributes of size, position, and color. The class should store the following information as instance variables: Your Hat class should provide the following methods:

When your Hat class compiles, write an applet RandomHats that uses your Hat class to create and draw 5 hats. Four of the hats should be random and the fifth should be a black hat with a magenta band positioned in the middle of the applet. For each of the four random hats, make the height a random value from 75 up to 150 (but not including), x from 0 up to 550, y from 0 up to 300. To generate the color generate a random value (between 0 and 255, inclusive) for each color component (amount of red, amount of green, and amount of blue), then use the Color constructor with three parameters (as we did in Lab 3) to get a random color. You should declare local variables inside the paint method of the applet to store each of the color components then use those variables as parameters to the Color constructor. Note: You need to generate the random values for a hat, then use them to instantiate a hat, then get new values and instantiate another hat (copy and paste will come in handy). Do this to get 4 random hats. Instantiate and draw the fifth hat in the center of the applet and invoke the addBand method to draw the band on the hat.

Of course, you also need an html file so you can run the applet. In the html file make the applet width 600 and height 400. SUGGESTION: First just get one hat in your applet then go back and add the others.

Be sure your program is appropriately documented.

Hand-in: Hard copy of your Hat class and your RandomHats applet. Also tar your post lab directory that contains all of your files (.java, .class, and .html) and email the tar file to your instructor with cpsc120 post5 in the subject line.