CMSI 186: Homework Assignment #4
Learning Outcomes: Students will (1) understand the mathematics of simple
motion, collisions and friction; and (2) gain further experience with clean division of labor
, or
what is known as separation of concerns
in an object-oriented design philosopy using Java.
Problems About Soccer Balls [Discrete Simulations]
In this assignment, you will program a discrete simulation of a physical system in order to answer some
questions about its behavior. For this homework, accomplish the following activities to make a Java
program, SoccerSim, that solves the following problem:
Simultaneously, on a perfectly flat playground, at time 00:00:00.0 (hrs:mins:secs), an arbitrary
number of soccer balls are kicked, all at different speeds and directions. We wish to find out, via
a discrete simulation of the system, whether a collision will ever take place, and, if so, where and
when. Each ball has a radius of 4.45 inches and weighs one pound. The center of the playground is
presumed to be the point (x,y) = (0.0,0.0). The following additional conditions apply:
- Data about each ball will be given to your program via four consecutive arguments, namely the x- and
y-coordinates of the ball's starting position [measured in feet],
followed by its speeds in the x- and y-directions
[measured in feet per second].
- Friction acts to slow each ball down until it comes to rest. Your program should simulate
friction as a force that continuously decreases each ball's speed at the rate of
one per cent per second until it is traveling less than
one inch per second, at which point it comes to rest.
- If present, a final argument specifies the time slice [in seconds]. If missing, your program should
use a default time slice of one second. The maximum valuel allowed is 1800.0 seconds.
- There must be a pole, a stationary object somewhere on the field.
- As always, your program should check validity of the arguments.
- A typical invocation of your program might look like this:
java SoccerSim 300 300 -1 -2 5 10 3 6 10.0
which indicates one ball initially at (300, 300), moving at the rate of one foot west and two feet south
per second; just one other ball initially at (5, 10), moving at the rate of three feet east and six feet
north per second; with the simulation to be driven by a ten-second time slice.
- Your program should output:
- An initial report that gives the locations of all objects, including the initial
velocity of each ball.
- After every time slice, a report showing the location and velocity of every ball.
- A final report indicating the simulated time of the first collision, the objects
involved and their locations; or, the message NO COLLISION IS POSSIBLE, giving the
simulated time at which the program made that discovery.
- There will be some natural opportunities for using Java objects. For example, you will probably want
to reuse some portion of your
Clock class [assuming we do the ClockSolver
exercise this semester]. If you don't have that class, you can optionally make a Timer
class to handle clock ticking and time output and formatting. You will need a new public class
named Ball.java.
- Although you may not collaborate with classmates about the code itself, you are encouraged to
add to the construction of test cases for the simulation.
Notes:
- The field size will be 1000 feet by 1000 feet. Note that this means the location specifications are
in feet, and are ±500 feet in both the X and Y directions.
- The pole must be located on the field somewhere, but it's up to you as to where. It can be at a
random location, a fixed location, and may have any dimensions you like, from a point up to the size
of a ball [radius 4.45 inches].
- Making the pole a point means you must have a separate collision
detection loop for the pole since the pole will have zero X and Y dimensions.
Submission Guidelines: Make a sub-directory in your repository as mentioned above,
called homework04 and commit your source code into it. DON'T FORGET TO ADD A COMMIT COMMENT!