Presentation is loading. Please wait.

Presentation is loading. Please wait.

Teaching with the AP® Marine Biology Simulation Case Study

Similar presentations


Presentation on theme: "Teaching with the AP® Marine Biology Simulation Case Study"— Presentation transcript:

1 Teaching with the AP® Marine Biology Simulation Case Study
Materials mostly from: Alyce Brady (Case Study Author) Kathy Larson (Case Study Teachers' Guide Author) Presenter: Joe Kmoch

2 Goals of this Presentation
Introduce the goals and objectives of the Marine Biology Simulation case study Provide an overview of the various chapters Discuss how to use the case study to teach object-oriented programming

3 Case Study as Educational Tool
Describes a real situation Provides an interesting example from which to draw certain lessons Provides a context for comparing theoretical ideas against real-world experience Long been used in a variety of disciplines, esp. professional disciplines like Law, Medicine, Engineering, etc. In general, they describe an actual situation and give students an opportunity to apply what they’ve learned in class to the real-world or see how they compare.

4 Benefits of an AP CS case study
Example of a largish program First case study introduced in 1994 WHY????? Opportunity to discuss tradeoffs (design, performance issues, readability, etc) Example of good coding, design, and documentation practice Context for covering design and testing * readability vs performance, etc * master/apprentice relationship is one of most effective teaching environments known

5 Benefits (continued) Approximation of master/apprentice relationship
Rich source of assignments AP: source of non-trivial exam questions * readability vs performance, etc * master/apprentice relationship is one of most effective teaching environments known

6 Goals for Java MBS Similar to C++ MBCS Teachers can pick it up faster.
Students can use it as they learn Java. Different from C++ MBCS There are differences in language. There are differences in curriculum. Additional goals because we have a second audience: HS teachers who are learning Java (many of whom are familiar with the C++ MBCS) be similar be different

7 The Story A CS student, Pat, gets a summer job working for marine biologists. Hired to enhance an existing program that simulates fish movement in a bounded environment. Needs to understand existing program Designs, codes, and tests modifications Occasionally Pat turns to an experienced programmer, Jamie, for help. Narrative is Pat’s report of summer job. Jamie enhances the master/apprentice relationship aspect; provides information when Pat is confused, makes some suggestions showing great foresight, and, at the end, even offers to make needed changes to the graphical user interface.

8 The Modules (Chapters)
Experiment with existing program (run it) Guided tour of the code by Jamie Add breeding and dying Add two new kinds of fish (inheritance) Provide alternative representations (unbounded environment, others) Chap 5: Alternative representations * interfaces * follow-up part-time job during school year * AB only

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

10 Exercise Let’s run it! (using fish.dat)
Chapter 1 Exercise Let’s run it! (using fish.dat) Complete the table. (using onefish.dat) Guide them to the BlueJ version of the MBS (where will it be?) CAN DO EARLY IN SCHOOL YEAR How does the program appear to model the body of water (the "bounded environment")? What do the grid lines represent? Where can fish be in the model? Can there be more than one fish in the same place at the same time? Do all fish face the same direction? Does a fish's direction appear to matter? Pick one fish and watch it for several steps. Does it move in every step? How far does it move? Does it always move in the same direction? Can it move in any direction? Is it more likely to move in one direction over another?

11 Exercise: onefish.dat

12 How Can You Use Chapter 1? Introduction or Review of:
Running a Java Program Problem-Solving, Deductive Reasoning Multiple interacting objects End of chapter -- Review of: Basic constructs (object construction, method invocation, loops, etc.)

13 Calling constructors ENV_COLS);
BoundedEnv env = new BoundedEnv(ENV_ROWS, ENV_COLS); Fish f1 = new Fish(env, new Location(2, 2)); Fish f2 = new Fish(env, new Location(2, 3)); Fish f3 = new Fish(env, new Location(5, 8));

14 Loops and invoking methods
for ( int i = 0; i < NUM_STEPS; i++ ) { f1.act(); f2.act(); f3.act(); display.showEnv(); }

15 Chapter 2 Guided Tour “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.” Need to have covered * basic flow control constructs * basic parts of a class * 1D arrays There’s an optional supplement you can use earlier, if you want * constructing objects * invoking methods * uses two of the simpler utility classes

16 What classes are necessary?
Chapter 2 What classes are necessary? 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. There are other useful, but less important "utility classes." Utility classes are “black-box” -- class documentation only.

17 One step in the simulation
Chapter 2 One step in the simulation Simulation knows about the environment. It asks the environment for a list of all the fish. (Technical detail: a Java array.) Asks each fish to act (which, for now, just calls move). At end of step, asks the display object to display the environment. This diagram is on p. 23 Compare to code for the Simulation class on p. 21.

18 Exercise Role-playing exercise Chapter 2
Developed by Dave Levine and Steve Andrianoff at St. Bonaventure University (upstate NY)

19 public static void main(String[] args)
{ BoundedEnv env = new BoundedEnv(ENV_ROWS, ENV_COLS); Fish f1 = new Fish(env, new Location(2, 2)); Fish f2 = new Fish(env, new Location(2, 3)); Fish f3 = new Fish(env, new Location(5, 8)); SimpleMBSDisplay display = new SimpleMBSDisplay(env, DELAY); Simulation sim = new Simulation(env, display); for ( int i = 0; i < NUM_STEPS; i++ ) sim.step(); }

20 What do core classes look like?
Chapter 2 What do core classes look like? Simulation: step method - very simple loop through all the fish public void step() { // Get all the fish in the environment and ask each // one to perform the actions it does in a timestep. Locatable[] theFishes = theEnv.allObjects(); for ( int index = 0; index < theFishes.length; index++ ) ((Fish)theFishes[index]).act(); } theDisplay.showEnv(); Debug.println(theEnv.toString()); Debug.println("———— End of Timestep ————"); Simulation: (p. 21) almost identical to C++ MBCS has no run method Environment: IS AN INTERFACE ! (list of methods is on p. 24) class documentation -- think header file! some methods are very similar, some not so similar environment of generic objects (almost), so method names are numObjects, allObjects, objectAt, etc. Fish: (list of methods is on p. 27)

21 What do core classes look like?
Chapter 2 What do core classes look like? Environment: black box; only look at class documentation – Appendix C (until Chap 5) Direction randomDirection() Direction getDirection(Location fromLoc, Location toLoc) Location getNeighbor(Location fromLoc, Direction compassDir) ArrayList neighborsOf(Location ofLoc) int numObjects() Locatable[] allObjects() boolean isEmpty(Location loc) Locatable objectAt(Location loc) void add(Locatable obj) void remove(Locatable obj) void recordMove(Locatable obj, Location oldLoc) // other tested methods not shown; Simulation: (p. 21) almost identical to C++ MBCS has no run method Environment: IS AN INTERFACE ! (list of methods is on p. 24) class documentation -- think header file! some methods are very similar, some not so similar environment of generic objects (almost), so method names are numObjects, allObjects, objectAt, etc. Fish: (list of methods is on p. 27)

22 What do core classes look like?
Chapter 2 What do core classes look like? Fish: has color, direction move method is a little more complicated, has more helper methods Simulation: (p. 21) almost identical to C++ MBCS has no run method Environment: IS AN INTERFACE ! (list of methods is on p. 24) class documentation -- think header file! some methods are very similar, some not so similar environment of generic objects (almost), so method names are numObjects, allObjects, objectAt, etc. Fish: (list of methods is on p. 27)

23 Fish (page 27) public Fish(Environment env, Location loc)
public Fish(Environment env, Location loc, Direction dir) public Fish(Environment env, Location loc, Direction dir, Color col) private void initialize(Environment env, Location loc, Direction dir, Color col) protected Color randomColor() public int id() public Environment environment() public Color color() public Location location() public Direction direction() public boolean isInEnv() public String toString() public void act() protected void move() protected Location nextLocation() protected ArrayList emptyNeighbors() protected void changeLocation(Location newLoc) protected void changeDirection(Direction newDir)

24 Constructors Chapter 2 Initialize instance variables
Add the fish to the environment A Fish constructor adds the fish to the Environment, so there is no reason to add it again. It is critical that the fish and the environment agree on the fish’s location at all times. This is why a fish adds itself in its constructor, thus ensuring that the fish and the environment agree on the location as soon as the fish is constructed.

25 Fish constructor (pg 28)calls initialize
private void initialize(Environment env, Location loc, Direction dir, Color col) { theEnv = env; myId = nextAvailableID; nextAvailableID++; myLoc = loc; myDir = dir; myColor = col; theEnv.add(this); // object is at location myLoc in // environment }

26 move method (page 34) Get next location to move to (call nextLocation)
Chapter 2 move method (page 34) Get next location to move to (call nextLocation) If next location is different from this location, move there (call changeLocation) change direction (call changeDirection) changeLocation and changeDirection are not really necessary, but are needed later for subclasses, so we introduce them here. All they do is to modify the instance variables, but since the data is private the subclasses would not be able to do this directly. act is just a call to move (p. 33) Code for move is on p. 34

27 move() Location nextLoc = nextLocation();
if ( ! nextLoc.equals(location()) ) { Location oldLoc = location(); changeLocation(nextLoc); Direction newDir = environment().getDirection(oldLoc, nextLoc); changeDirection(newDir); }

28 Chapter 2 nextLocation method Get list of empty neighboring locations (call emptyNeighbors) Remove location behind fish from list If there are any empty neighbors left, randomly choose one; otherwise return current location Pseudo-code for nextLocation is on p. 35 Code for emptyNeighbors is on p. 36 Code for nextLocation is on p. 37 (Code for changeLocation and changeDirection is on p. 39)

29 Chapter 2 Analysis Question: Why does the Fish class need an emptyNeighbors method? Why doesn’t nextLocation just call the neighborsOf method from the Environment class? Have them work in pairs and talk over their results. Consult with a neighboring pair if you’re unsure about what you are doing. For Ex. 5 on p. 45, will probably need a new configuration file that is almost completely full. Copy an existing data file and edit it to fill it further.

30 Analysis Question-ANSWER:
Chapter 2 Analysis Question-ANSWER: The neighborsOf method returns all valid neighboring locations, not just those that are empty. The emptyNeighbors code that obtains a fish’s empty neighbors from the environment could have been included in nextLocation but we want each method to perform one well-defined task. Including the code from emptyNeighbors in nextLocation would have over-complicated nextLocation and made it less readable. Have them work in pairs and talk over their results. Consult with a neighboring pair if you’re unsure about what you are doing. For Ex. 5 on p. 45, will probably need a new configuration file that is almost completely full. Copy an existing data file and edit it to fill it further.

31 Analysis Questions/Exercises
Chapter 2 Analysis Questions/Exercises What’s the difference between Analysis Questions and Exercises? Have them work in pairs and talk over their results. Consult with a neighboring pair if you’re unsure about what you are doing. For Ex. 5 on p. 45, will probably need a new configuration file that is almost completely full. Copy an existing data file and edit it to fill it further.

32 How Can You Use Chapter 2? Review of:
Basic constructs (object construction, method invocation, conditions, loops, class layout, etc) Public and Private and Protected Access Levels Java arrays and array lists First three sets of topics are really prerequisites, but you can use the chapter to review them.

33 How Can You Use Chapter 2? Introduction or Review of:
Object-oriented design Interfaces (high-level view) Class variables, constants, and static methods Using Random Numbers The ArrayList class Testing Object-oriented design: whole chapter, but particularly pp (in Excerpted handout), 46 Constants: p. 25 Class (static) variables and methods: pp (in addition to Excerpted handout) NOTE: There are other important static methods that the case study does NOT cover! For example, the methods in the Math class (abs, floor, etc) and the methods in the Arrays and Collections classes (e.g., binary search and sort). Interfaces: somewhat superficial introduction (pp. 22, 24); Chapter 5 goes into interfaces in more detail. ArrayList: p. 36 Testing: pp

34 Breeding and Dying Problem Specification: A fish should ...
Chapter 3 Breeding and Dying Problem Specification: A fish should ... have a 1 in 7 chance of breeding, breed into all empty neighboring locations, attempt to move when it does not breed, never move backwards, and have a 1 in 5 chance of dying after it has bred or moved. Short chapter -- point is just to make some modifications to the code before going further. Could do this chapter AFTER the next one on inheritance; if done after inheritance, could have students implement this as an extension (subclass) of Fish rather than as modifications to Fish. Version of Fish class used on AP Exam is the version as of the end of Chap. 3 (with breeding and dying) -- see appendix.

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

36 “A” Exam Summary Class Implementations Simulation (Chap 2)
Fish (Chaps 2 & 3) DarterFish (Chap 4) SlowFish (Chap 4) Class Documentation A number of utility classes Only Chapters are required for A course (see next slide for why) 7 Utility Classes Whose Documentation students read Debug Direction EnvDisplay (single method) Environment Location Locatable (single method) RandNumGenerator (single method)

37 Environment Implementations
Chapter 5 Environment Implementations Multiple environment implementations Environment Interface Bounded: 2D array (matrix) -- existing Unbounded: ArrayList of Fish -- Pat develops this implementation Only Chapters are required for A course. Chapter 5 deals with traversal of 2D array (2D arrays are no longer required in A curriculum); overall topic is “alternative data representations” has some discussion of efficiency, algorithm analysis exercises ask students to implement environments using … (see next slide)

38 “AB” Exam Summary Classes and documentation from “A” Exam
Additional Class Interfaces/Implementations Environment BoundedEnv UnboundedEnv Class Documentation One new utility class New Utility Class SquareEnvironment

39 What resource materials will the students be given for the AP CS Exams in Java?
For the Java AP CS Exam the students will have a Java Subset Quick Reference Guide for either AP CS A or AP CS AB. The reference guide will contain the Java Language classes presently printed at the end of the AP Java subsets. In addition to this, the students taking the APCS-A Exam will receive the MBS Case Study Appendix B, C, E, and a modified G. For the APCS-AB Exam they will receive the MBS Case Study Appendix B, C, D, F, G.


Download ppt "Teaching with the AP® Marine Biology Simulation Case Study"

Similar presentations


Ads by Google