CP2003 - Tutorial Eleven: Night of the Living Thread


One large programming question this week relating to threads. Consider the example BouncingBall.java - your task for this tutorial is re-write this java file so that there is a class member variable (a vector of point objects) which stores the position of each newly created ball.

Remember that a class member variable is a member variable which is shared between all instances of that particular class.

Each time a new thread (ball) it should add it's position to the vector and should update this position each time it gets to move. Also, when it moves you will need to check to see if the ball is colliding with any other balls (iterate through the vector) then you should do something cool (like make the balls bounce off each other or make them turn red and disappear or, even better, make them speed up by increasing their priorities (as well as turning them red, because they're mad) etc.).


Copyright © 2000. James Cook University. All rights reserved.