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

Slides:



Advertisements
Similar presentations
Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Advertisements

Big Ideas behind Inheritance. Can you think of some possible examples of inheritance hierarchies?
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Two examples of Problem Solving in Programming H. Chad Lane University of Pittsburgh CS7: Introduction to Programming.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Chapter 1 Program Design
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
1 CSC 222: Computer Programming II Spring 2005 Searching and efficiency  sequential search  big-Oh, rate-of-growth  binary search  example: spell checker.
Copyright 2010 by Pearson Education 1 Assignment 11: Critters.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
1 Some Patterns of Novice Programs Author : Eugene Wallingford ; Dan Steinberg ; Robert Duvall ; Ralph Johnson Source : PLoP 2004 Advisor : Ku-Yaw Chang.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
ACM/JETT Workshop - August 4-5, Marine Biology Case Study (MBCS) A Discussion.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Introduction to Programming with Java. Overview What are the tools we are using – What is Java? This is the language that you use to write your program.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Chapter 9: Polymorphism Coming up: Creating Objects Revisited.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
ArrayList, Multidimensional Arrays
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Computer Science II 810:062 Section 01. How is CS I different from CS II? When you teach Java there are a series of decisions that have to be made…
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
Marine Biology Simulation Part II: Assignment, Milestone 1 Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
CS305j Introduction to Computing Classes 1 Topic 23 Classes – Part I "A 'class' is where we teach an 'object' to behave." -Rich Pattis Based on slides.
Teaching with the AP ® Marine Biology Simulation Case Study Materials mostly from: Alyce Brady(Case Study Author) Kathy Larson(Case Study Teachers' Guide.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
Lesson 6 – Libraries & APIs Libraries & APIs. Objective: We will explore how to take advantage of the huge number of pre-made classes provided with Java.
1 Recursion Recursion is a powerful programming technique that provides elegant solutions to certain problems. Chapter 11 focuses on explaining the underlying.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
Interfaces and Inner Classes
Programming Techniques Lec03 Procedural Abstraction Software Engineering Fall 2005.
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Aquarium Lab Series Developed by Alyce BradyAlyce Brady of Kalamazoo CollegeKalamazoo College.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
GridWorld Case Study The case study is a program that simulates actions and interactions of objects in a two- dimensional grid. During a single step of.
CS 146: Data Structures and Algorithms June 11 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Clue Paths. Memory Alias Review Remember that it’s possible for two unique variables to point to the same memory location myList MyClass mc 0x100 someFn.
Interfaces & Sub-types Weiss sec Scenario Instructor says: “Implement a class IntegerMath with two methods pow and fact with the following signatures:
Chapter 9 Introduction to Arrays Fundamentals of Java.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
GridWorld.
Teaching with the AP® Marine Biology Simulation Case Study
AP Case Study Overview Barbara Ericson Jan 2005
Object-Oriented Programming
Week 15 – Monday CS221.
Interfaces and Inheritance
Marine Biology Simulation Part II: Assignment, Milestone 1
Presentation transcript:

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

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

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

Benefits of an AP CS case study n Example of a largish program u First case study introduced in 1994 u WHY????? n Opportunity to discuss tradeoffs (design, performance issues, readability, etc) n Example of good coding, design, and documentation practice n Context for covering design and testing

Benefits (continued) n Approximation of master/apprentice relationship n Rich source of assignments n AP: source of non-trivial exam questions

Goals for Java MBS n Similar to C++ MBCS u Teachers can pick it up faster. u Students can use it as they learn Java. n Different from C++ MBCS u There are differences in language. u There are differences in curriculum.

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.

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

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

Exercise Let’s run it! (using fish.dat ) Let’s run it! (using fish.dat ) Complete the table. (using onefish.dat ) Complete the table. (using onefish.dat ) Chapter 1

Exercise: onefish.dat

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

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

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

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

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

One step in the simulation Chapter 2

Exercise n Role-playing exercise Chapter 2

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(); }

What do core classes look like? Simulation: step method - very simple loop through all the fish 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 ————"); } Chapter 2

What do core classes look like? n 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; Chapter 2

What do core classes look like? n Fish: u has color, direction  move method is a little more complicated, has more helper methods Chapter 2

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)

Constructors n Initialize instance variables n Add the fish to the environment u u A Fish constructor adds the fish to the Environment, so there is no reason to add it again. u u 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. Chapter 2

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 }

move method (page 34) 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

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

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

Analysis Question: Why does the Fish class need an emptyNeighbors method? Why doesn’t nextLocation just call the neighborsOf method from the Environment class? 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. Chapter 2

Analysis Questions/Exercises n What’s the difference between Analysis Questions and Exercises? Chapter 2

How Can You Use Chapter 2? n Review of: u Basic constructs (object construction, method invocation, conditions, loops, class layout, etc) u Public and Private and Protected Access Levels u Java arrays and array lists

How Can You Use Chapter 2? n Introduction or Review of: u Object-oriented design u Interfaces (high-level view) u Class variables, constants, and static methods u Using Random Numbers  The ArrayList class u Testing

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

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

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

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

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

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

“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

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

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

“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

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.