Assignment Specification
Write an applet with 4 menus. The first menu allows the user to select a type of fish behavior, Regular, Chameleon, Dizzy, and Random Swim and then create fish of that type. The second menu allows the user to select any combination of Chameleon, Dizzy, or Random Swim and create a fish with that behavior.
The third menu allows the user to create a leader fish, and the fourth menu allows the user to create a follower fish. When a leader fish is created, it will take on the behavior currently specific by the MultiFish menu. When a fish with follower behavior is created, it will "follow" the leader on the screen. There will only be one fish with leader behavior allowed on the board at any one time. So the last leader created will be the leader that all of the follower fish must follow.
Additionally, when a fish is clicked by the user, it will become the new leader and take on the (composite) behavior specified by the MultiFish menu. That is, it will change its behavior while the program is running!
ToDo:
- Fish that does one thing
- Fish that does multiple things
- Create Behaviors (represented by a class)
Code:
- LeaderMenuObserver
- FollowerMenuObserver
- SingleFishBehaviorMenuObserver
- createMenu(Single..., Multi..., Leader..., Follower...);
UML
- Dotted open arrow shows implements
- SingleMenu implements SingleFish...
- new SingleMenu() <- pass in the class that does the implementing into createMenu();
- Behavior has composition with Fish
- Fish extends CSE115.FishBowl.Fish
- example in Applet:
- this.createMenu( new SingleMenu(), new MultiMenu(), new LeaderMenu(), new FollowerMenu() );
Other stuff:
- Behavior -interface with one method
- void ChangeFish(Fish fishy);
- implement this behavior, depending on class,
- DizzyBehavior implements Behavior
- ChangeFish(...);
- ChameleonBehavior implements Behavior
- ChangeFish(...);
- RegularBehavior implements Behavior
- ChangeFish(...);
- Code:
public void ChangeFish(Fish fishy) {
}
public class Thing {
private Foo _f;
private Thing(){
_f = new Foo();
}
}
*Fish.Java:
public class Fish extends cse115....Fish {
private Behavior _behavior;
public Fish {
_behavior = new RegularBehavior();
}
public void setBehavior (Behavior b) {
_behavior = b;
}
public void update(){
super.update();
}
}