10 likes | 128 Views
JVM. Marine Biology Case Study "Call Stack". SimpleMBSDemo2 - main method - creates BoundedEnv object - creates Fish object - creates Fish object - creates Fish object - creates SimpleMBSDisplay object - creates Simulation object - runs the simulation for i steps.
E N D
JVM Marine Biology Case Study "Call Stack" SimpleMBSDemo2 - main method - creates BoundedEnv object - creates Fish object - creates Fish object - creates Fish object - creates SimpleMBSDisplay object - creates Simulation object - runs the simulation for i steps • Fish – initialize method • initializes its own instance variables • adds itself to the Environment • BoundedEnv – add method • is the location empty? • put fish into the Environment • increment objectCount • Simulation – constructor • initializes its own instance variables • displays the simulation • Simulation – step method • get a list of all objects from the Environment • tell each object to act • displays the simulation BoundedEnv – neighborsOf method • Fish – emptyNeighbors method • ask the Environment for the • neighbors of this location • check each one to see if it is empty • Fish – act method • is the Fish in the Environment? • breed • if did not breed, then move • should the fish die? • die • Fish – isInEnv method • is the object in the Environment • at the specified location the same • object as this Fish BoundedEnv – isEmpty method • Fish – generateChild method • create a new Fish • Fish – breed method • should the fish breed? • if yes: get list of empty neighbors • breed into all empty neighboring locations Fish – nextLocation method - get a list of empty neighbors - get the opposite direction - get the location behind the fish - remove the location behind the fish - if no valid empty neighboring locations, return - otherwise, randomly pick one of the neighboring locations Direction – reverse method BoundedEnv – getNeighbor method • Fish – move method • get the nextLocation • move only if the nextLocation is NOT the • same as the current locaiton • change location • update the direction in case the fish turned • change the direction • BoundedEnv – recordMove method • is this fish the fish the old location and • is the new location if empty? • put fish in new location • clear fish from the old location Fish – changeLocation method - record the move Bound2edEnv – getDirection method • Fish – die method • remove this fish from the environment Bound2edEnv – changeDirection method B.Brenner 4/2004