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
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

Big Ideas behind Inheritance. Can you think of some possible examples of inheritance hierarchies?
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.
Design Patterns CMPS Design Patterns Consider previous solutions to problems similar to any new problem ▫ must have some characteristics in common.
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.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
Alice in Action with Java
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 1 Program Design
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.
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.
Georgia Institute of Technology Extending the Case Study Barbara Ericson January 2005.
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.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Chapter 9: Polymorphism Coming up: Creating Objects Revisited.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
ArrayList, Multidimensional Arrays
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.
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,
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
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.
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.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
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
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.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
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.
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:
© 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.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2002 Pearson Education, Inc. Slide 1.
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
Summary prepared by Kirk Scott
Lecture 12 Inheritance.
Agenda Warmup AP Exam Review: Litvin A2
Object-Oriented Programming
Java Software Structures: John Lewis & Joseph Chase
Interfaces and Inheritance
Chapter Three - Implementing Classes
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

Specialized Fish n Different patterns of movement  Darters ( DarterFish )  Slow fish ( SlowFish ) n Inheritance n Dynamic Binding 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

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