## CSE 131 Module 4: Input & Output

### Bumping Balls

In this lab you will simulate multiple bouncing balls, that may bump into each other or into the wall. The steps articulated below for completing this lab recommend that you develop the code in stages, so that you can test as you go and make sure you are on the right track.

You have the knowledge you need to do this assignment, but the assignment is written-up in a style usually seen for software specification: you are told what should happen, but it's up to you to make it happen.

As always, consult with TAs when you are stuck.

The code you submit must be your own! We are not interested in solutions you find on the Internet. We are interested in your implementation of these ideas.

#### Resources

• Do your work in the lab4 package of the labs source folder, in the BumpingBalls class.
• Review the implementation of BouncingBall, found in the book source folder, package book.ch1.
• Review the additions we made to BouncingBall to obtain DeluxeBouncingBall, found in the lecture source folder, package io.
• We added sound when an object changed direction.
• We replaced the ball by images.
• While there is some physics required for this lab, the information you need to know is simply the following:
• Two balls are colliding if the distance between the two balls' centers is less than the sum of the two balls' radii:

• The distance between two points can be computed using the distance formula.

#### Description

• Prompt the user for the number of balls that will be simulated in your program and the number of iterations for the simulation.
• For each ball, find a random place on the screen to place that ball.
• For each ball, compute a random velocity for that ball.
Based on what you have learned so far in this course, how will you keep track of the balls' positions and velocities?
• Finding a reasonable range of velocities may require some trial-and-error, or some thinking and experimentation using pencil and paper:
• If the balls move too fast, they might fly off the screen.
• If they move too slowly, the simulation will take forever for you to see something.
• Iterate the specified number of times, each time recomputing each ball's location
• When a ball collides with a wall, change its velocity as shown in the BouncingBall program.
• When a ball collides with another ball, change both its horizontal and vertical velocity component, as if the ball hit a corner of the screen.
• For extra fun, have the balls replaced by images you like. There are some in the images folder in your repo, but you are free to find others. Be sure to commit those to your repository.
• For extra extra fun, play sounds when balls collide. Some of those can be found in the sound folder.

• You must commit all of your work to your repository. It's best to do this from the top-most level of your repository, which bears your name and student ID.
• You must demo the commited work to a TA. Make sure the TA knows that your demo is for credit at this point.
• Follow the directions below to have your demo for this work recorded.

When you done with this lab, you must be cleared by the TA to receive credit.
• Fill in the form below with the relevant information
• Have a TA check your work
• The TA should check your work and then fill in his or her name
• Click OK while the TA watches

If you worked in a team using a group– repository:
• Your work must be committed in that repository for this demo.
• Each team member must complete this form and have the TA authenticate.
For example, if there are two of you, then the form must be submitted twice, so that each person's last name and 6 digit ID is captured with the repository name.
• The repository name must be included on each of the submissions.

group– Enter the name of your group repository here
 Last name 1