Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#

Slides:



Advertisements
Similar presentations
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Advertisements

Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Advanced Object-Oriented Programming Features
Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ISE 582: Web Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 4 JAVA Cup.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
A First Program Using C#
1 Programming James King 12 August Aims Give overview of concepts addressed in Web based programming module Teach you enough Java to write simple.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
ACM/JETT Workshop - August 4-5, Marine Biology Case Study (MBCS) A Discussion.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
Georgia Institute of Technology Extending the Case Study Barbara Ericson January 2005.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
IE 411/511: Visual Programming for Industrial Applications
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
Lecture 8: Object-Oriented Design. 8-2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Objectives “Good object-oriented programming is really.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.
1 NORMA Lab. 7 Generating Reports More Display Options File: NORMA_Lab6.ppt. Author: T. Halpin. Last updated: 2009 June 9.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Marine Biology Simulation Part II: Assignment, Milestone 1 Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Microsoft Visual Basic 2005 BASICS Lesson 1 A First Look at Microsoft Visual Basic.
Nifty Assignments: Marine Biology Simulation OOPSLA ‘04 Educators’ Symposium October 25, 2004 Eric Cheng Mathias Ricken Dung “Zung” Nguyen Stephen Wong.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
CS2110: SW Development Methods Inheritance in OO and in Java Part 2: Topics: Forms of inheritance Interfaces in Java.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Development with Eclipse Software Engineering Prof. Werner Krandick.
Teaching with the AP ® Marine Biology Simulation Case Study Materials mostly from: Alyce Brady(Case Study Author) Kathy Larson(Case Study Teachers' Guide.
Teaching with the AP ® Marine Biology Simulation Case Study Materials mostly from: Alyce Brady(Case Study Author) Kathy Larson(Case Study Teachers' Guide.
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Iterators, Iterator, and Iterable 2015-T2 Lecture 8 School of Engineering and Computer Science, Victoria University of Wellington COMP 103 Thomas Kuehne.
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
Topic 2 Collections. 2-2 Objectives Define the concepts and terminology related to collections Discuss the abstract design of collections.
Subclassing, pt. 2 Method overriding, virtual methods, abstract classes/methods COMP 401, Fall 2014 Lecture 9 9/16/2014.
Introduction to Objects and Encapsulation Computer Science 4 Mr. Gerb Reference: Objective: Understand Encapsulation and abstract data types.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
Development with Eclipse
Interfaces and Inheritance
Objects First with Java A Practical Introduction using BlueJ
Multi-form applications and dialogs
Introduction to Computer Science for Majors II
Objects First with Java A Practical Introduction using BlueJ
Objects First with Java A Practical Introduction using BlueJ
Presentation transcript:

Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#

“AP Computer Science with.NET and J#” Lecture 12: Extending the Marine Biology Simulation Case Study Microsoft.NET Workshops for Teachers

12-3 MicrosoftAP Computer Science with.NET and J# Workshop Track LectureTopic 7Algorithms and Algorithm Analysis 8Debugging and Exception Handling 9Applying Object-oriented Design Principles in Your Classes 10Using Inheritance to Design a Set of Classes 11MBS CS: the Marine Biology Simulation Case Study 12Extending the MBS CS 13Interfaces and Interface-based Programming 14Extending the MBS CS, Part 2 15Stacks, Queues and Invariants 16Linked Data Structures and the Linked-list 17Trees and Recursion 18Collection Classes and Iteration 19Additional Resources and Ideas

12-4 MicrosoftAP Computer Science with.NET and J# Lecture — Objectives “Part 2 of our discussion of the Marine Biology Simulation Case Study...” Topics: –Learning your way around –Modifying the Fish class

12-5 MicrosoftAP Computer Science with.NET and J# Part 1 Learning Your Way Around

12-6 MicrosoftAP Computer Science with.NET and J# Core Classes Here's the design of the core classes: SquareEnvironment BoundedEnvUnboundedEnvSimulation extends DarterFish Fish SlowFish extends depends on

12-7 MicrosoftAP Computer Science with.NET and J# Recall What the Core Classes Do… Fish classes: –Fish are the entities that move around in the environment –Fish are uniquely identified by an ID –Fish also have a location, a direction and a color SquareEnvironment classes: –An environment has a data structure to keep track of the fish Simulation class: –Contains the code to drive the simulation

12-8 MicrosoftAP Computer Science with.NET and J# Navigating Around There are various ways to learn your way around the MBS… Read the JavaDocs –HTML-based docs in the Documentation sub-folder Browse the code: –skim the source code files –use Visual Studio’s Object Browser : Let’s you view all the components, classes, interfaces, etc. View menu, Object Browser –use Visual Studio’s Class View Let’s you navigate source code by class & method (vs. by file) View menu, Class View –use Visual Studio’s Class Designer (if available in your version) Let’s you view a UML-like diagram of the code Project menu, Add New Item…, Class Diagram

12-9 MicrosoftAP Computer Science with.NET and J# Example: Class View Easier to navigate classes in class view… –controlled via Solution Explorer window –View menu, Class View (or click tab) –double-click method to jump to code

12-10 MicrosoftAP Computer Science with.NET and J# Demo! Navigating the MBS CS…

12-11 MicrosoftAP Computer Science with.NET and J# Part 2 Modifying the Fish Class

12-12 MicrosoftAP Computer Science with.NET and J# The Basics of the Simulation Each step of the simulation gets the fish to "act"… public class Simulation { private Environment theEnv; private EnvDisplay theDisplay;. public void step() { Locatable[] fish = theEnv.allObjects(); // fish in env… for (int i=0; i<fish.length; i++) // for each fish, act… { Fish f = (Fish) fish[i]; f.act(); // fish may move, eat, breed, die, do nothing, … } theDisplay.showEnv(); // now draw result of fish acting up! } } //class public class Simulation { private Environment theEnv; private EnvDisplay theDisplay;. public void step() { Locatable[] fish = theEnv.allObjects(); // fish in env… for (int i=0; i<fish.length; i++) // for each fish, act… { Fish f = (Fish) fish[i]; f.act(); // fish may move, eat, breed, die, do nothing, … } theDisplay.showEnv(); // now draw result of fish acting up! } } //class

12-13 MicrosoftAP Computer Science with.NET and J# The Fish Class The Fish class is the base class for the Fish hierarchy –All fish inherit common behavior like the ability to “act” (e.g. move) public class Fish { private int myId; private Location myLoc; private Direction myDir;. public void act() { this.move(); } protected void move() { Location nextLoc = this.nextLocation(); // at random… if (nextLoc.equals(this.myLoc)) ; // no sense moving if locations are the same else // move to new location… this.changeLocation(nextLoc); } public class Fish { private int myId; private Location myLoc; private Direction myDir;. public void act() { this.move(); } protected void move() { Location nextLoc = this.nextLocation(); // at random… if (nextLoc.equals(this.myLoc)) ; // no sense moving if locations are the same else // move to new location… this.changeLocation(nextLoc); }

12-14 MicrosoftAP Computer Science with.NET and J# Defining New Fish Defining new fish is surprisingly easy given MBS's OO design –and the polymorphic programming style used within MBS Idea behind defining new fish: –simulation treats all fish the same — just calls act() –new types of fish need only change act() ’s behavior! public class Simulation { public void step() { Locatable[] fish = theEnv.allObjects(); for (int i=0; i<fish.length; i++) { Fish f = (Fish) fish[i]; f.act(); }. public class Simulation { public void step() { Locatable[] fish = theEnv.allObjects(); for (int i=0; i<fish.length; i++) { Fish f = (Fish) fish[i]; f.act(); }.

12-15 MicrosoftAP Computer Science with.NET and J# Example #1 Short-lived fish… –Fish live only 7 time steps, then die Extending app so that Fish are short-lived: 1.add a private instance field called age to all fish objects 2.make sure age is properly initialized to 0 (use initialize( ) method) 3.increment age in act() 4.act() then checks if fish has reached 8, and if so calls die( ) –code follows on the next slide…

12-16 MicrosoftAP Computer Science with.NET and J# Short-lived Fish public class Fish { protected int age;. private void initialize(...) { age = 0;. } public void act() { age++; if ( isInEnv() ) // then fish is still alive & part of environment if (age == 8) environment().remove(this); // remove THIS fish from env… else move(); } //act public class Fish { protected int age;. private void initialize(...) { age = 0;. } public void act() { age++; if ( isInEnv() ) // then fish is still alive & part of environment if (age == 8) environment().remove(this); // remove THIS fish from env… else move(); } //act

12-17 MicrosoftAP Computer Science with.NET and J# Build, Run & Test Build, run, create an environment, add some fish, & step…

12-18 MicrosoftAP Computer Science with.NET and J# Demo! Defining a short-lived fish…

12-19 MicrosoftAP Computer Science with.NET and J# Example #2 A better design would allow fish’s life-time to be overriden –i.e., allow new types of fish to control their own destiny –lots of ways to do this… One approach: –recode act( ) to call another method M to see if fish has died –if so, fish is removed from environment –if not, fish lives on –method M can be overriden by sub-classes to control life-time

12-20 MicrosoftAP Computer Science with.NET and J# Redesigned Fish Class By default, fish live forever –sub-classes override died( ) if they want to change this behavior… public class Fish {. public void act() { age++; if ( isInEnv() ) { if (died()) environment().remove(this); else move(); } // sub-classes can override to control life-time protected boolean died() { // by default, fish never die... return false; } public class Fish {. public void act() { age++; if ( isInEnv() ) { if (died()) environment().remove(this); else move(); } // sub-classes can override to control life-time protected boolean died() { // by default, fish never die... return false; }

12-21 MicrosoftAP Computer Science with.NET and J# Demo! Short-lived fish revisited…

12-22 MicrosoftAP Computer Science with.NET and J# Other Examples MBS CS includes other kinds of fish: –DarterFish dart ahead or turn around –SlowFish move sloooowly… –just need to update GUIForm.jsl to use these classes: a)view code behind GUIForm.jsl (within MBSGUI component) b)locate main( ) method that starts up MBS… c)uncomment code that associates a DisplayMap with DarterFish and SlowFish d)uncomment code to add “DarterFish“ and “SlowFish” to FishNameArray e)uncomment code to add images for DarterFish and SlowFish to FishImageArray f)run!

12-23 MicrosoftAP Computer Science with.NET and J# Demo! Adding DarterFish & SlowFish to the GUI…

12-24 MicrosoftAP Computer Science with.NET and J# Summary Case studies are an important tool for learning AP Marine Biology Simulation is a good app to study –component-based –elegant object-oriented design –large and complex enough to yield non-trivial study –lots of room for exploration & extension.NET and J# are a good vehicle for working with AP MBS –J# supports Java language & required subset of Java Class Library –.NET provides rich GUI –Visual Studio 2005 offers excellent programming environment

12-25 MicrosoftAP Computer Science with.NET and J# Resources Web site for slides, demos, associated lab exercises: – – –

12-26 MicrosoftAP Computer Science with.NET and J# That’s it! Next up: LectureTopic.. 13Interfaces and Interface-based Programming......