Simulation and animation of a ball bouncing under the influence of gravity - demo by Monday 11/17

You may have a programming partner for this lab; if you do not have a suitable partner and would like one, please let me know.

Introduction

Your task as in Chapter 9, is to implement and animate a user controlled simulation of a ball falling under the influence of gravity and bouncing until it stops. Let the user start and stop the simulation by pressing a button. You may find that a Circle animates better than a FilledCircle. Assume the elasticity of the collision with the floor is 90%; thus if the downward velocity of the ball were 100 when it hit the floor, its subsequent upward velocity would be 90.

Design

As always, before starting to write code, you should do enough design work to avoid wasting many frustrating hours going down blind alleys. Never start programming before you have a clear idea what you are trying to accomplish and how you will approach the problem. To design this program, in addition to sketching the GUI and deciding which classes to use, you must also have some idea what discrete time simulation is.

GUI

The problem description says there must be a Button to start and stop the simulation; so, obviously you will need a Button (or two).
Draw a box that is slightly smaller than the Frame, keep the ball in the box.

Details

  1. Use constants for the edges of the box, so that you won't have numbers scattered all over your code. Like this:
    static final int UP=50;
    static final int LEFT=40;
    static final int FLOOR=700;
    static final int RIGHT=500;
    Feel free to use different numbers. How big should the Frame be? The bigger it is, the farther the ball will be able to fall before it hits the floor; but the particular size is not critical. But it should be bigger than the box it surrounds!

How to get credit

Demo your program AND send me email, with your source code attached, telling which extra credit you completed and who your programming partner was (if you had one).

Extra credit

  1. Add vx, so that the ball goes sideways some.
  2. Add a switch to control whether the ball leaves a trail (make the switch turn off the super.paint(g) in public void paint(Graphics))
  3. Make the elasticity 100% (so the ball does not slow down when it bounces)
  4. Turn off the gravity (give the ball an initial velocity in the x and y direction)
  5. Have 100 balls instead of one! Make them different colors; now you have molecules in a box!
  6. Make those molecules interact; they might bounce off each other, or attract, or repel...