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 Case Study as Educational Tool n describes a real situation n provides an interesting example from which to draw certain lessons n provides a context for comparing theoretical ideas against real-world experience

3 Case Studies in AP CS n try to give the illusion of being a real-world situation (MBCS) or real-world tool (BigInt) n must be simplified and cleaned-up enough to be readable and understandable for HS students

4 Benefits of an AP CS case study n example of a largish program n opportunity to discuss tradeoffs (design, performance issues, readability, etc) n example of good coding, design, and documentation practice n approximation of master/apprentice relationship n context for covering design and testing n rich source of assignments n source of non-trivial exam questions

5 Goals for Java MBS n provide benefits described in prev. slides n be similar to C++ MBCS u teachers can pick it up faster u can use it as they learn Java n be different from C++ MBCS u highlight differences in language u highlight differences in curriculum

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

7 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)

8 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)

9 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

10 Exercise 1 n Let’s see it run! n Complete the table on p. 11.

11 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

12 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

13 One step in the simulation Chapter 2

14 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

15 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

16 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

17 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

18 Exercise 2 n Let’s see some sample exercises. u Do Questions 1, 7, 8, 9 on p. 31 u Read over exercises on p. 32 n What’s the difference between Analysis Questions and Exercises?

19 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

20 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

21 Breeding and Dying n Test Plan u Testing random behavior (Chap 2) u Black-box testing u Code-based testing Chapter 3

22 Breeding and Dying n Sample Exercise: Introduce a new instance variable in Fish keeping track of how many times a fish bred. Initialize it in the constructor and increment it in the breed method. Modify the debugging statement in the die method to print the number of times the fish bred. Run your simulation for 20 timesteps. What is the maximum number of times a fish bred in your test run? What is the minimum number? Are these values you would have expected given the probability of breeding in each timestep? Chapter 3

23 Exercise 3 n Let’s see it run!

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

25 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

26 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

27 Exercise 4 n Let’s see it run! n Let’s see some sample exercises. u Questions 1 and 2 on p. 75 u Read over exercises on p. 76

28 “A” Exam Summary n Class Implementations  Simulation (Chap 2)  Fish (Chaps 2 & 3)  DarterFish (Chap 4)  SlowFish (Chap 4) n Class Documentation u A number of utility classes

29 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

30 Environment Implementations n Exercises u Very large bounded environment (list or sparse matrix) u Sorted list for unbounded environment with binary search u BST for unbounded environment u Hash map for unbounded environment Chapter 5

31 “AB” Exam Summary n Classes and documentation from “A” Exam n Additional Class Interfaces/Implementations  Environment  BoundedEnv  UnboundedEnv n Class Documentation u One new utility class

32 Exercise 5 n Let’s see it run! n Let’s see some sample exercises. u Questions 1 and 2 on p. 80 u Read over exercises on p. 104

33 Key Features n Introduces “large” program to intro students n Covers key topics; highlights new ones u Object interaction u Inheritance, dynamic binding u Interfaces u Design issues u Testing u Data Representation

34 Want to use it? n www.collegeboard.com/ap/students/ compsci/download.html


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

Similar presentations


Ads by Google