CS 140 - Homework 5 - Due Thursday October 9

A Random Walk

Brownian motion is the random movement of a particle in its environment. For example, a dust particle suspended in a liquid exhibits Brownian motion. In this homework assignment you are going to simulate Brownian motion drawing a pixel on the screen and randomly moving in one of eight possible directions; to the left, right, up, down, or on the diagonals of upper right, lower right, upper left, or lower left.

Have your simulation repeatedly make a random move a large number of times (for example 100,000) inside a 600-by-600 picture. When the simulation is finished write some fancy text in the center of the picture indicating it is done. If a particle tries to move off of the edge of a picture you should also quit the simulation and indicate that it has finished. See what my version looks like by double clicking on the file

T:\Harcourt\Fall2008\CS140\HW5\run.bat

Hints

Grading

  1. Name your class HW5 and save it in a file on the T: drive HW5.java. Watch out for the case, "HW" is capitalized.
  2. Turn in a stapled printout at the beginning of class.
  3. Use a comment at the top to indicate your name and date.
  4. Make sure your program is properly indented (use DrJava's code indent feature). This aids readability.
  5. Is your program general? For example I should be able to change one line at the top to change the size of the picture and everything should still work fine.
  6. Does your program work correctly?