1 / 1

SimpleMBSDemo2 - main method - creates BoundedEnv object - creates Fish object

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.

ciqala
Télécharger la présentation

SimpleMBSDemo2 - main method - creates BoundedEnv object - creates Fish object

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

More Related