CIT 591 Ninth Java Assignment: Wator
David Matuszek, Fall 2002


The idea:

"Wator" (a misspelling of "water") is a classic predator-prey simulation. In this simulation, there are sharks and tuna. Sharks move, eat tuna, and reproduce; they might starve to death. Tuna move and reproduce, and they always have enough to eat. Neither tuna nor sharks ever die of old age.

In this simulation, you will display an N by N array representing the ocean, and markers of two different sizes representing the sharks and the tuna.

Details of program behavior:

Implement this program as an applet.

The ocean is an NxN array, where N is an input parameter from the HTML to the Applet. Each 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 following parameters should be set from the GUI:

The GUI should have these buttons

A scrollbar to control the speed of the simulation would be nice, but is optional.

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

At each step, each shark will

Details of program implementation:

The program should be written using the Model-View Controller design pattern. Put the view and the controller each in their own separate class; the model part will consist of more than one class.

The controller

The class you create that extends Applet should be controller. Your applet's init method should create model and view objects, set up and display the GUI, attach listeners to the buttons; once it has done that, its job is done.

The model

Notice that tuna and sharks share a lot of the same behaviours. Define a class Fish with subclasses Tuna and Shark, and implement the necessary methods for movement and reproduction in Fish.

You can, of course, implement any other classes that you need. Note that at least one of your classes--the one in charge of making sure every fish has a chance to do something--should extend Observable, and should notify observers when it is time to redraw the ocean.

The view

The View class should extend Canvas and implement Observer, and should have a paint(Graphics) method. This method draws the ocean (with grid lines or not, as you choose) with tuna and sharks in it.

You are welcome to borrow any code you find helpful from my RabbitHunt program. However, you should be aware of one problem in that program: since I did not properly extend the Canvas class, there are times when the screen does not redraw properly. You can avoid this particular problem my making sure your View class extends Canvas.

Due date: Friday, December 6.