Java assignment: Wator
David Matuszek,
Fall 1998, Villanova University

"Wator" (a misspelling of "water") is a simple predator-prey simulation. It was first described by A. K. Dewdney, in his "Computer Recreations" article in the December, 1984 issue of Scientific American. In this version, there are sharks and tuna. Sharks move, eat tuna, and reproduce; they might starve to death. Tuna move and reproduce; they never starve, but might get eaten. Neither tuna nor sharks die of old age.

This simulation will read the following input parameters from the command line (or equivalent):
  • Size of the ocean.   
  • Number of steps.
  • Initial number of tuna.   
  • Tuna gestation period.
  • Initial number of sharks.
  • Shark gestation period.
  • Shark starvation period.
The ocean is an NxN array (the size N is an input parameter). It "wraps" to form a torus: a cell on the right edge is adjacent to cells on the left edge, and a cell on the bottom edge is adjacent to cells on the top edge. A location in the array can be empty, or it can hold one tuna or one shark (but not both). At the beginning of the simulation, put the tuna and sharks in random locations in the ocean.

The simulation progresses in a series of "steps." At each step, each tuna will

At each step, each shark will

Run the simulation for the given number of steps, and at each step print out the number of tuna and the number of sharks. Stop the simulation early if you run out of tuna or run out of sharks.

Turn in:
  • A listing of your source code.
  • A listing of your printed results.
  • Documentation for your program, created with javadoc.

It's the Java language that I'm concerned with, not the simulation. So if some details of the simulation aren't clear, just do something reasonable.

Note: The next Java assignment will build on this one, so it is important to get this one working.