CPSC 120 Assignment #2
Completed Assignment: Friday October 27, 2006 by 4:00 p.m.
Phase II
In the next major phase of the project you need the following two files
to create the cloud and raindrop objects:
Raindrop.java This file defines a class that models a simple
raindrop with the following characteristics:
- A raindrop has a location that will be randomly generated
in the constructor when the raindrop is created. This means that
the constructor needs some information about the region the
raindrop will be in (certainly the raindrop should not be
off the screen for one thing). Hence the constructor needs to
have four parameters to specify the bounds for generating the
random position - it needs the leftmost x value and the width
of the region (in order to generate a valid x position for the
raindrop) and it needs the uppermost y value and the height of
the region (to generate a valid y position).
- A raindrop is a simple oval 8 pixels wide and 10 pixels high.
- All raindrops are the same color somewhere in the light-blue/
gray spectrum. You will need to create your own color for
the raindrops.
Cloud.java This file defines a class that
models a simple cloud formation with the following characteristics:
- A cloud will be represented by its location (x, y) specifying the
upper left hand corner of the (invisible) rectangle that encloses the cloud,
the width of the rectangle, and the height of the rectangle. The
cloud will also have a color but the color must be one of the following:
white, light gray, or dark gray.
- The constructor for the Cloud class will take the positioning and
size information as parameters plus an integer to represent the
color (a 1 will mean a white cloud, a 2 will mean a light gray cloud,
and a 3 will mean a dark gray cloud). The constructor must take the
integer passed in and use it to assign the appropriate color to the
instance variable (which should be an object of type Color). If the
parameter is not valid (not a 1, 2, or 3) the color should default
to white.
- A cloud will be drawn as at least three overlapping ovals positioned
in some way to make something that looks like a simple cloud formation.
The maximum width of the cloud must be the width specified above and
the maximum height must be the height specified. Similarly the leftmost
position must be the given x and the uppermost position the y. Basically
what this means is that you have a rectangle (which isn't explicitly
drawn) that extends across from x to x + the width and down from
y to y + the height and your cloud must touch the boundaries of this
rectangle (without going over). Drawing of the cloud should be
done in a draw method (naturally!).
- A cloud can "rain" - that is, it can produce raindrops beneath it.
This will be modeled with a rain method. The rain method
will instantiate at least 10 raindrops (and have the draw method
of the Raindrop class draw them). The raindrops will be positioned
underneath the cloud. Hence when instantiating the raindrops the
rain method must pass information to the raindrop constructor letting
it know the position and size of the valid region for the raindrop.
Because of this the rain method needs to know how far the rain
can fall (it can compute where the bottom of the cloud is but the
Cloud class has no information about the size of the applet it
is being used in so it doesn't know how far the rain can fall
below the cloud). Hence the rain method must have two parameters -
one will be an integer representing the distance the rain can fall. The
other must be the Graphics page (since the rain method will need to
send the page object to the draw method of the Raindrop class).
Implementation Strategy: You should work on this in the following
phases. Don't move on to a subsequent phase until the earlier phases
are complete.
- Phase 1: Create the Cloud class without the "rain" method. Test
it by instantiating and drawing some clouds of various colors in
the beach scene.
- Phase 2: Create the Raindrop class. Test it by instantiating and
drawing several raindrops in the beach scene (or you can create another
applet for this).
- Phase 3. Add the rain method to the Cloud class. Test it
out by invoking the rain method on your clouds.
Final Phase: In the final phase you will use your classes
to create two scenes. The specifications for these will be given
to you the Monday after break. The beach scene will be similar
to the one you already have except that there will be some
conditional logic based on what kind of day it is.
Academic Integrity Reminder!!! Programming
assignments are to be your own work (this includes Phase I of this
assignment). You may get help on the specifics
of the assignment from no one except the instructor. You may not show
your program to anyone or look at anyone else's program or share ideas
with anyone about how to write the program.