Presentation is loading. Please wait.

Presentation is loading. Please wait.

AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.

Similar presentations


Presentation on theme: "AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College."— Presentation transcript:

1 AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College

2 The Story n A CS student, Pat, gets a summer job working for marine biologists. n Hired to enhance an existing program that simulates fish movement in a bounded environment. u Needs to understand existing program u Designs, codes, and tests modifications n Occasionally Pat turns to an experienced programmer, Jamie, for help. n Narrative is Pat’s report of summer job.

3 The Package n Code for the “existing” program u Source for core classes u Jar files for “black box” & GUI classes n Javadoc documentation for most classes n Data Files n Instructions for compiling/running n Narrative (pdf file)

4 The Modules (Chapters) n Experiment with existing program (run it) n Guided tour of the code by Jamie n Add breeding and dying n Add two new kinds of fish (inheritance) n Provide alternative representations (unbounded environment, others)

5 First Day on the Job n “[The program] was designed to help the marine biologists study fish movement in a bounded environment, such as a lake or a bay.” n Jamie not available until the next day. n Pat is given instructions for running the program and told where to find data files. Chapter 1

6 Exploring the MBS Files n Examine the folders from the zip file n Black Box Source Code n GUI Source n JavaMBS --- Contains Source Code n Documentation (HTML Docs) n Narrative (2002_MBS.pdf) n Open the Index.html and look around n Open the 2002_MBS.pdf and look around n Look at the data files

7 Guided Tour n “The biologists think of the environment as a rectangular grid, with fish moving from cell to cell in the grid. Each cell contains zero or one fish.” Chapter 2

8 What classes are necessary? To model fish swimming in a bounded environment, the program has Fish objects and an Environment object. To model fish swimming in a bounded environment, the program has Fish objects and an Environment object. The purpose of the program is to simulate fish moving in the environment, so the program also has a Simulation object. The purpose of the program is to simulate fish moving in the environment, so the program also has a Simulation object. n There are other useful, but less important "utility classes." Chapter 2

9 Run the Initial MBS n Run SimpleDemo1 with Fish that simply move (use OrigFishLE3.mcp) n Examine the code, notice no simulation class Chapter 2

10 Run the Second MBS n Run SimpleDemo2 with Fish that simply move (use OrigFishLE3.mcp) n Examine the code, notice the use of the simulation class Chapter 2

11 One step in the simulation Chapter 2

12 What do core classes look like? Simulation: step method - very simple loop through all the fish (see p. 21) Simulation: step method - very simple loop through all the fish (see p. 21) n Environment: black box; only look at class documentation (until Chap 5) n Fish: u has color, direction  move method is a little more complicated, has more helper methods Chapter 2

13 Constructors n Initialize instance variables n Add the fish to the environment u a fish knows about its environment u must always be in an environment to be in a consistent state n See pp. 27-28 Chapter 2

14 move method Get next location to move to (call nextLocation ) Get next location to move to (call nextLocation ) n If next location is different from this location,  move there (call changeLocation )  change direction (call changeDirection ) Chapter 2

15 nextLocation method Get list of empty neighboring locations (call emptyNeighbors ) Get list of empty neighboring locations (call emptyNeighbors ) n Remove location behind fish from list n If there are any empty neighbors left, randomly choose one; otherwise return current location Chapter 2

16 Run the GUI Version MBS n Run MBSGUI with Fish that simply move (use OrigFishLE3.mcp) n Examine the code, Black Box Chapter 2

17 Breeding and Dying n Problem Specification: A fish should... u have a 1 in 7 chance of breeding, u breed into all empty neighboring locations, u attempt to move when it does not breed, u never move backwards, and u have a 1 in 5 chance of dying after it has bred or moved. Chapter 3

18 Breeding and Dying Pseudo-code for act method if this is the 1 in 7 chance of breeding if this is the 1 in 7 chance of breeding call the breed method call the breed method else else call the move method call the move method if this is the 1 in 5 chance of dying if this is the 1 in 5 chance of dying call the die method call the die method Chapter 3

19 Lets look at the Fish Class Modifications for Breeding & Dying Examine the modified fish class that includes breeding and dying Marine Biology Case Simulation\JavaMBS\Code\ DynamicPopulation\fish.java Chapter 3

20 Specialized Fish n Different patterns of movement  Darters ( DarterFish )  Slow fish ( SlowFish ) n Inheritance n Dynamic Binding Chapter 4

21 Specialized Fish DarterFish DarterFish u darts two cells forward if possible u or darts one cell forward u or reverses direction (without moving) Chapter 4

22 Specialized Fish SlowFish SlowFish u has only a 1 in 5 chance of moving out of current cell  otherwise movement is the same as Fish Chapter 4

23 Run the Dynamic Fish Version n Marine Biology Case Simulation\JavaMBS\Code\DynPopLE3 n Note darter and slow fish n Create and SAVE New Environments

24 Environment Implementations n Multiple environment implementations u Environment Interface u Bounded: 2D array (matrix) -- existing u Unbounded: ArrayList of Fish -- Pat develops this implementation Chapter 5

25 “AB” Exam Summary n Class Implementations  Simulation (Chap 2)  Fish (Chaps 2 & 3)  DarterFish (Chap 4)  SlowFish (Chap 4) n Additional Class Interfaces/Implementations  Environment  BoundedEnv  UnboundedEnv n Class Documentation u One new utility class

26 MBS Debugger n debug.turnOn( ) n debug.turnOff( ) n Demonstrate the Debugger

27 MBS Role Playing n Get to better understand the Case Study by “Role Playing” a Simulation Step


Download ppt "AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College."

Similar presentations


Ads by Google