How to extend the marine biology case study beyond the Fish class
Mostly you need to change classes that assume things are Fish. In the GUI classes that I (Barbara Ericson) changed I used an interface Drawable which inherits from Locatable and adds the methods needed to draw things using the GUI. In the simulation classes I added an interface Actionable which inheritied from Drawable and adds the act() and die() methods.
I also added AbstractDrawable which pulled out the fields from Fish and methods that are needed to draw things. I added AbstractActionable that also adds the act and die methods. So when you create new non-fish classes have them inherit from AbstractActionable. Or, if you want non-fish classes that don't do anything (like rocks or walls) extend AbstractDrawable.
I modified these classes:
Fish.java
MBGGUI.java
Simulation.java
BoundedEnv.java
I also modified classes in the mbsgui.jar.
I added new classes and interfaces:
AbstractActionable.java
AbstractDrawable.java
AbstractDrawableDisplay.java
Actionable.java
Drawable.java
DrawableImageDisplay.java
I added some classes that you can use but don't have to include:
HungryFish.java
Mammal.java
Orca.java
Starfish.java
Wall.java
WallDisplay.java
Mouse.java
SmartMouse.java
MouseDisplay.java
SmartMouseDisplay.java
I added a subclass HungryFish to Fish which has a field that keeps track of how hungry it is and when it is hungry enough and there is a neighbor it eats the neighbor (causing the neighbor to die) and moves into the neighbor's space.
I also added a non-fish Starfish (starfish aren't really fish) which extends the AbstractActionable class and Orca which extends Mammal (which extends AbstractActionable). Objects of the Starfish class try to sink to the bottom and stay there. Objects of the Mammal class need to come up to breathe. Subclasses of Mammal can specify how the maximum number of steps between breaths before they die.
I added a Mouse class and a subclass SmartMouse. You can use these to simulate mice in a maze. The mice currently leave the maze when they reach the top right corner. I added a MouseDisplay class to draw the mice. I also added a SmartMouseDisplay class.
To create your own classes subclass AbstractActionable if you want them to act() and die(). See Starfish for an example. Or subclass AbstractDrawable if the objects are in the environment but don't act. See Wall for an example.
Link to this Page