- Practice writing constructor and method definitions
- Learn to use random numbers
- Practice graphics programming
For this assignment you will complete the implementation of a simple screen saver
application. You are given an Eclipse project that includes ScreenSaver and Ball classes.
The ScreenSaver class includes the main program that creates some Ball objects, and jumps
them around the screen. Your job is to complete the implementation of the Ball class according
to the following UML design:
Complete the exercises in order, testing after each step.
- Download the eclipse project for this lab (ScreenSaver.zip) and import the
project into eclipse (File -> Import -> Existing Projects into Workspace).
- Compile and run the application. It should simply blank the screen until you press any key.
- Complete the field definitions, including field initializers for some reasonable default values. The random
field is already done for you. Make sure the application still compiles and runs without any errors.
The application should still show only a blank screen.
- Complete the draw method. A ball should draw itself as a solid circle according to its color, size, and
current position on the screen. Now when you run your program, you should see a single ball in the default
color and position. Actually, the ScreenSaver draws several balls, but they will all be on top of each
- Complete the moveToRandomPosition method. A ball should move to a random location within the given
window when it receives this message. The ball should only update its coordinates (relative to the given
window). It should not erase or redraw itself. The ball can determine the window's size by sending it
appropriate messages. When this step is complete, your program should start filling the screen with circles of the
default ball size in the default color. At this point when a ball moves, the screen saver redraws it at the new
location, but can't erase it from its old position.
- Complete the erase method. A ball should erase itself by drawing a solid black circle according to
its size and position. Now your program should display 10 balls of the default size and color that jump around
- Add a constructor method that takes no parameters and sets the radius of the ball to a random value between 20
and 50. Now the program should display 10 balls of various sizes, all in the default color.
- Modify the constructor method so that each ball gets a random color.
- Modify the draw method so that colored smiley faces are drawn instead of just circles. Make these
simple smiley faces with just a smile and two solid black eyes (not the more elaborate ones from last week's lab).
Make sure the size and position of the smile and eyes are in proportion to the size of the face.
When you are finished
- Demonstrate the final version of the program after making all the additions and modifications in the exercises.