OOD – Colliding Balls Simulation

Follow these steps:

  1. Download the attached BlueJ project file, Collision.zip to your java folder. Double click on it.
  2. Open the folder and double-click the BlueJ package icon.
  3. Replace “_YI” suffix with your initials in all the files that use it.
  4. Study the code for the Ball_YI, BallDriver_YI, and CollidingBall_YI classes.
  5. Modify the Ball_YI class as follows:
    — a. When any ball collides with another, the ball changes direction. Their behavior after the collision is up to you but it has to be noticeable. There are two types of collisions, elastic and inelastic. It is also up to you to choose the type.
    — b. When any ball collides with each other, the ball changes to a random color and stays that color until it collides again.
    — c. When any ball collides with the walls, the ball changes to a random color. NOTE: It is ok if all the balls change color at the same time.

    Submission:
  6. A short QuickTime video.
  7. Attach Ball_YI, and CollidingBall_YI classes.

Collision Detection:

 These diagram should help you with the calculations for the conditions you need to implement to capture the the balls within a “d” distance of each other:

   or

More Hints: look at the problem from the cartessian plane perspective: