AP - PowerPoint PPT Presentation

About This Presentation
Title:

AP

Description:

Narrative is Pat's report of summer job. The Package. Code for the 'existing' program ... First Day on the Job ' ... Jamie not available until the next day. ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 35
Provided by: Alyce
Learn more at: http://max.cs.kzoo.edu
Category:
Tags: day | first | of | summer

less

Transcript and Presenter's Notes

Title: AP


1
AP Marine Biology SimulationCase Study
  • Alyce Brady
  • Kalamazoo College

2
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

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

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

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

6
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 Pats report of summer job.

7
The Package
  • Code for the existing program
  • Source for core classes
  • Jar files for black box GUI classes
  • Javadoc documentation for most classes
  • Data Files
  • Instructions for compiling/running
  • Narrative (pdf file)

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)

9
First Day on the Job
Chapter 1
  • 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 1
  • Lets see it run!
  • Complete the table on p. 11.

11
Guided Tour
Chapter 2
  • 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.

12
What classes are necessary?
Chapter 2
  • 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."

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

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

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

17
nextLocation method
Chapter 2
  • 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

18
Exercise 2
  • Lets see some sample exercises.
  • Do Questions 1, 7, 8, 9 on p. 31
  • Read over exercises on p. 32
  • Whats the difference between Analysis Questions
    and Exercises?

19
Breeding and Dying
Chapter 3
  • 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.

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

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

22
Breeding and Dying
Chapter 3
  • 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?

23
Exercise 3
  • Lets see it run!

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

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

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

27
Exercise 4
  • Lets see it run!
  • Lets see some sample exercises.
  • Questions 1 and 2 on p. 75
  • Read over exercises on p. 76

28
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

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

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

31
AB Exam Summary
  • Classes and documentation from A Exam
  • Additional Class Interfaces/Implementations
  • Environment
  • BoundedEnv
  • UnboundedEnv
  • Class Documentation
  • One new utility class

32
Exercise 5
  • Lets see it run!
  • Lets see some sample exercises.
  • Questions 1 and 2 on p. 80
  • Read over exercises on p. 104

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

34
Want to use it?
  • www.collegeboard.com/ap/students/
  • compsci/download.html
Write a Comment
User Comments (0)
About PowerShow.com