Balloon Race Applet Lab
Follow the steps below to create a balloon race applet that partially meets
the specifications on which you based your object-oriented design last week.
- Read through the
BalloonApplet
and Balloon
classes and run the applet
in the BalloonApplet.html
web
page to understand what the BalloonApplet
class is doing.
- Download the
RandNumGenerator
class to your project as well.
- Modify the
BalloonApplet
class so that the width of a balloon
is 3/4ths the height of a balloon. The overall height of a balloon,
including the balloon and its basket should be twice the height of the balloon
alone.
- Implement the
move
method in the Balloon
class.
- In the
BalloonApplet
class, fix the calculation of the pixel
coordinates for the upper-left corner of a balloon, which should depend on
the balloon's current location. Remove the getRandomX
method.
- In the
paint
method, set the color of the balloon
appropriately, not to a random color.
- Add a finish line to the applet. (This requires changes in two different
methods.) Label the finish line with an "F," similar to the
"S" label for the starting line. Don't put the finish line
all the way at the right margin; leave enough room for a balloon to cross
it and still be displayed in the applet. (How much space do you need
to leave to the right of the finish line to accomodate any single move over
the line that a balloon might make?)
- In the
step
method, calculate the leading edge (right edge)
of the balloon and then test whether the leading edge has crossed the finish
line. Remove all the references to keeping track of the number of simulation
steps that have been run.
- Draw a basket beneath the balloon. The height of the basket should
1/4th the overall height of the balloon. (This leaves a blank space
between the basket and the balloon that is also 1/4th the overall height.)
If you want to, add two lines from the edges of the balloon down to the basket,
to connect the basket to the balloon.
- Modify the program to handle an array of balloons. Put three or four
balloons in the array. The animation should stop when the leading edge
of any one of the balloons crosses the finish line.
- If you have time, you may experiment with increasing the size of the applet,
painting a background, or improving the appearance of the applet in any other
way you choose.
Print out the two classes that you have changed. Remember to update the
authors, versions and any other pertinent comments.