| CIT 591 Assignment 8: Wator Applet Comments Fall 2003, David Matuszek |
Comments added November 18, 2003:
I intended that the initial state of the ocean be one that could be reached during the course of the simulation. During the simulation, a location in the ocean could (1) be empty, (2) contain algae, (3) contain a little fish, (4) contain a big fish, or (5) contain a big fish and algae. This was not clear from the assignment, and it isn't really important anyway (but try to start with the right number of each item). However, under no circumstances should an ocean location contain two or more fish.
If a location contains both algae and a big fish, both should be visible. Don't draw one so that it completely covers the other.
A big fish can move where there is a little fish (and eat it). A little fish will not move where there is a big fish (and get eaten). As the assignment says, "A fish cannot move to a location containing an equal-sized or larger fish."
I described the class Ocean as "the interface to the model."
Ocean is the interface (general English term) to the entire
model that is used by the GUI; it is not an interface (Java term),
but a class (Java term). In other words, Ocean is
a class, and the only access the GUI has to the model is via the class
Ocean. (Of course, the model may have many other classes as well, but
Ocean is the only one the GUI "knows about.")
Gestation period (length of pregnancy) is the same for all big fish, but individual fish may differ in when they are due to give birth. For example, the gestation period might be 9 turns, but one fish will be ready to give birth in 3 turns, another in 7, etc. For simplicity, fish don't have to "grow up" before they become pregnant; under favorable conditions, a fish will give birth when it is 9 turns old. Similar comments hold for little fish gestation period, big fish starvation period, and little fish starvation period.
Because the Ocean class is the only interface to the model,
it contains methods that rightfully belong elsewhere. For example, it has a
method. Clearly, this should be in the BigFish class (assuming
you have a BigFish class, which you probably do, but it isn't required).
The correct way to handle this situation is to delegate responsibility
to the correct class, for example:
public void setBigFishGestationPeriod(int numberOfTurns) {
BigFish.setGestationPeriod(numberOfTurns);
}
where public static void setGestationPeriod(int numberOfTurns) is a static (why?) method in BigFish.
Incidentally, the "correct" singular form of algae is alga (one alga, two algae), but as algae is essentially a mass noun (one alga?), only biologists ever use the singular form. I used the singular form in exactly one place in the assignment, mostly to try to be very clear that algae "growth" is like fish "reproduction": You get another, separate, new alga in an adjacent square.
Comments from November 14, 2003:
Big fish don't eat algae. If a big fish moves to a location that contains algae, both of them coexist quite happily until the big fish moves away.
Please write an applet, not an applications. (I thought that was clear!)
I confusingly used "view" in two different senses:
I said that View (the class) should extend
Canvas. This is where you should do your drawing.I said that the view should display the numbers of big fish, little fish, and algae, and the turn number. I did not mean to imply that these must be done in the View (Canvas). They are best done in a panel somewhere close to the Canvas.
Canvas inherits getWidth() and getHeight()
methods from Component. You will almost certainly want to use these
in order to calculate where to draw the various things in your ocean.
When you create the ocean (from the other half of the program), you specify the number of rows and columns. I expected these to be set somewhere in the "GUI half" of the program, but I did not intend for them to be settable by the user. You can the ocean size settable by the user if you want, but you certainly don't need to. (Personally, I would specify these in the HTML file as parameters to be passed to the Applet, but you can do what you like.)
I forgot to specify how fish reproduction happens. If it is time for a fish to reproduce, and if the fish can move to an adjacent location, then one of those two locations contains the parent fish, and the other location contains the child fish. This is why the fish has to be able to move--we need two adjacent locations for the two fish. I don't care if the parent moves and the baby is left behind, or if the parent stays put and the child gets the adjacent square--that's an unimportant detail.
The "baby" fish is little if the parent is little; it is big if the parent is big. These are two different species. The baby is not at all hungry when it is first born, so it has the full "starvation period" before it needs to eat.
Please do not give your source code to anyone. (Your partners are welcome
to see your source code, but don't give away copies.) You can give your
.class files to your partners--that's all they need in order to
use your half of the assignment to make a working program.