CIT 591 Notes on the Wator Assignment
David Matuszek, Fall 2002

"GUI" stands for "Graphical User Interface." The GUI is the thing that appears on the screen. It is not the Applet class, or any other class. Where the assignment says:

The following parameters should be set from the GUI:

it means the parameters should be set from the graphical user interface. In other words, the person using the program should be able to set these parameters from the graphical user interface. It does not mean that the values are set by assignment statements in the Applet class.

The fact that I specify three buttons (New, Start, Stop) that should be in the GUI does not imply that these are the only things in the GUI.

You should be able to run the simulation repeatedly, without having to quit the program and restart it. Where the assignment says:

The GUI should have these buttons

it means that when the New button is clicked, you should get the current values of the parameters (initial number of tuna, tuna gestation period, etc.) from the GUI, and use those values to create a new simulation with a new initial number of tuna, etc.

The GUI should have a button labeled Stop. This does not imply that the button should call the deprecated Thread method stop(). When a feature is "deprecated," that means you should not use the feature. There is no necessary connection between the label on a button and the name of a method.

An applet always requires an HTML file. The HTML can contain parameters that the Applet can read with the getParameter method--see my Applet lecture or the description in the Java API for details. Where the assignment says:

The ocean is an NxN array, where N is an input parameter from the HTML to the Applet.

it means that the ocean size should be a parameter in the HTML file, and you should use getParameter to get that array size. It also means that the number of rows in the array is the same as the number of columns in the array, so you only need to supply one number.

The getParameter method returns a String. To convert the String to an integer, see my Applet lecture or the description in the Java API for details.

Although an applet always requires an HTML file, you do not have to create this yourself. Compile your program in BlueJ, right-click on the class of yours that extends Applet, choose Run Applet, and look at the dialog box that appears. You should be able to figure out what to do from here.

For obvious reasons, you should create the "ocean" array before you try to display it on the screen. It would be a good idea to create this array very early in your init() method, even before you create the GUI. Once init() finishes, Java will try to call repaint() to display your GUI. If you wait too long to create the ocean array, and repaint() is called, a variety of bad things may occur--I can't be more specific than that, because the results will depend on the details of your program.

The tuna gestation period, shark gestation period, and shark starvation period are best measured in "steps." One "step" involves giving each fish (tuna or shark) in the ocean a chance to move and/or reproduce.

Remember that it is impossible to instantiate (create an object of) an abstract class. The class Fish is supposed to be abstract. This means you cannot create a new Fish(). However, your Tuna and Shark classes can extend (and complete) Fish, and then you can create new Tuna objects and new Shark objects.

Your main Model class should extend Observable, and your View class should implement Observer. Note that this is not enough to get the View to update properly--you have to use addObserver to tell your View class that it should observe your Model. See my Applet lecture or the description in the Java API for details.

Some students have been using a Vector of Tuna objects and another Vector of Shark objects. That's allowable--you can do it that way if you want to. However, the assignment strongly suggests that you create an N by N array to represent the ocean, and the obvious thing to put in the ocean array is Fish objects (I can't think what else you might use this array for). If you also use Vectors, you are keeping redundant information spread across two Vectors and an array.

It is in general a bad idea to try to keep the same information in different forms within a program, because then you have to update the information in more than one place, and you have to be sure that the various copies are consistent with one another. This makes your program harder to debug and maintain. It is a better idea to keep a single copy of each piece of information (such as the location of a shark), and convert it to different forms as needed.

My advice is to use only a two-dimensional array to keep track of your fish. Again, this is not a requirement, and you can use as many Vectors or other data structures as you like in this program; but you may be doing things the hard way.

According to the assignment:

You are welcome to borrow any code you find helpful from my RabbitHunt program.

I should have added that borrowing code without understanding what it does is unlikely to be helpful. It is better to first figure out what you need to do, then look at the RabbitHunt program to figure out how to do it. Simply copying code wholesale is unlikely to be helpful.

In "A Thurber Carnival," the humorist James Thurber described how his aunt had no sense of direction, so when she tried to drive somewhere, she picked a car that looked like it knew where it was going, and followed it. (She got lost a lot.)

Moral: Don't program like Thurber's aunt drives.