Lab 9 Post-Lab Assignment: Drawing Circles
Due Monday, November 10, 2002
Write a Circle class that stores the following information as
instance variables:
- radius
- x coord of upper left-hand corner
- y coord of upper left-hand corner
- color
Your Circle class should provide the following
methods:
- A parameterless constructor that generates random values for the
radius, color, x, and y. Make the radius between 100 and 200, x between
0 and 600, y between 0 and 400. Remember that you can pass a (random)
integer to the Color constructor to get a random color.
IMPORTANT: Your random number generator must be declared at the class
level (not inside the constructor), and must be declared static. So
its declaration and initialization
should appear with the declarations of radius, color, x, and y, and
should look like this:
private static Random generator = new Random();
- A draw method that draws the circle at its x,y coordinate in its
color. Note that you need a Graphics object to draw (like the
page parameter of the paint method), so your draw method
will have to take a Graphics object as a parameter.
When your Circle class compiles, write an applet DrawCircles that
uses your Circle class to create and draw 10 circles.
This code should be very simple; the
paint method will contain a loop with just two statements -- create
a Circle, then draw it. Don't forget to pass the Graphics object to
draw.
Be sure your program is appropriately documented.
Hand-in:
- Hard copy of your program.
- Tar your post lab directory that contains all of your files (.java,
.class, and .html) and email it to your instructor with
cpsc120 post9 in the subject line.