Georgia Institute of Technology Extending the Case Study Barbara Ericson January 2005.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Object Oriented Programming
SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
AbstractClassesInterfacesPolymorphism1 Abstract Classes, Interfaces, Polymorphism Barb Ericson Georgia Tech April 2010.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Advanced Object-Oriented Programming Features
CPSC150 Abstract Classes and Interfaces Chapter 10.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
CPSC150 Abstract Classes Chapter 10. CPSC150 Directory Example (note: your assignment does not have all of this) DirectoryEntry name phone public void.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Abstract Classes and Interfaces
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
ACM/JETT Workshop - August 4-5, Marine Biology Case Study (MBCS) A Discussion.
Inheritance using Java
Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Intro to OOP with Java, C. Thomas Wu
Georgia Institute of Technology AP CS Exam Overview Barbara Ericson March 2005.
Inheritance Abstract Classes Check out Inheritance from SVN.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
CreatingClasses-part11 Creating Classes part 1 Barb Ericson Georgia Institute of Technology Dec 2009.
Object Oriented Programming Lecture 5: BallWorld.
CSC 142 Computer Science II Zhen Jiang West Chester University
Inheritance (Part 4) Abstract Classes 1.  sometimes you will find that you want the API for a base class to have a method that the base class cannot.
Georgia Institute of Technology Movies part 2 Barb Ericson Georgia Institute of Technology April 2006.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
Peyman Dodangeh Sharif University of Technology Fall 2014.
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
CreatingSubclasses1 Barb Ericson Georgia Institute of Technology Dec 2009.
Inheritance and Access Control CS 162 (Summer 2009)
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.
Coming up: Inheritance
Topics Inheritance introduction
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
Georgia Institute of Technology More on Creating Classes part 3 Barb Ericson Georgia Institute of Technology Nov 2005.
CompSci Reading from Files  import java.io.File;  Declare a file File fileOfCats = new File(”cats.txt”);  Use file – pass it as an argument to.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 3 – Extending classes.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Georgia Institute of Technology Comic Strip Analysis and Design Inheritance, Abstract Classes, and Polymorphism part 2 Barb Ericson Georgia Institute of.
Copyright 2009 by Pearson Education Building Java Programs Chapter 9: Inheritance and Interfaces Lecture 9-1.
Georgia Institute of Technology Comic Strip Analysis and Design Inheritance, Abstract Classes, and Polymorphism part1 Barb Ericson Georgia Institute of.
CS 116 Object Oriented Programming II Lecture 9 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
Modern Programming Tools And Techniques-I
Week 14 - Monday CS 121.
Interfaces and Inheritance
Barb Ericson Georgia Institute of Technology May 2006
Barbara Ericson AP CS Exam Overview Barbara Ericson Georgia Institute of Technology.
Inherited Classes in Java
Advanced Programming Behnam Hatami Fall 2017.
CS18000: Problem Solving and Object-Oriented Programming
Breakout in Greenfoot Barb Ericson
Inheritance Inheritance is a fundamental Object Oriented concept
An Example of Inheritance
More on Creating Classes
More on Creating Classes part 3
Presentation transcript:

Georgia Institute of Technology Extending the Case Study Barbara Ericson January 2005

Georgia Institute of Technology Ways to Extend the Case Study Subclass Fish –Add HungryFish that eat other fish when they are hungry enough –Add BottomFish that stay on the bottom –Add SickFish that spread disease to neighbors Add non-Fish classes –Walls (extend AbstractDrawable) –Snorkelers (extend AbstractActionable) –Dolphins (extend Mammal)

Georgia Institute of Technology How to Subclass Fish Create a new class that extends Fish –Like HungryFish Add any fields needed by the new class Add constructors that call super to initialize the inherited private fields Override the act method –public void act() Override generateChild to create this kind of fish –protected void generateChild(Location loc) Add any methods needed by act()

Georgia Institute of Technology Adding Subclasses of Fish Edit MBSGUI.java –Add the new class name to fishClassNames String[] fishClassNames = {"Fish", "HungryFish", "DarterFish", "SlowFish"}; –Add a way to display the new class Custom drawn one DisplayMap.associate("HungryFish", new RoundFishDisplay()); Gif image DisplayMap.associate("SlowFish", new FishImageDisplay("smallfish.gif", Direction.EAST));

Georgia Institute of Technology Adding HungryFish Add a field to say how hungry this fish is –private int hunger = 0; Add a field to say when ready to eat –private static final int NEED_TO_EAT = 5; Override the act() method –Increase the hunger each time the method is called –If hungry enough eat a random fish neighbor Move to the neighbor’s location and reset hunger to 0 –Otherwise use the inherited move method

Georgia Institute of Technology Fish and HungryFish

Georgia Institute of Technology Adding Non-Fish The problem is the assumption in many classes that you will only have Fish or subclasses of Fish To solve this I needed to change the GUI classes –So use mbsguigt.jar instead of mbsgui.jar in your classpath –Replace Fish, BoundedEnv, and MBSGUI, and Simulation

Georgia Institute of Technology Added Interfaces and Classes Interfaces –Drawable inherits from Locatable –Actionable inherits from Drawable New Classes –AbstractActionable the class to use to create non-fish objects that can act() and die() –AbstractDrawable the class to use to create non-fish objects that don’t act() –DrawableImageDisplay the class to use to display gifs for non-fish objects

Georgia Institute of Technology Sample New Classes Added a Mammal Class –Need to come to the surface to breathe –Extends AbstractActionable Added a Starfish Class –Which drops to the bottom and moves along the bottom –Extends AbstractActionable Added an Orca Class –Extends Mammal

Georgia Institute of Technology Sample New Classes

Georgia Institute of Technology Adding Walls The Wall class extends AbstractDrawable Displayed by WallDisplay which just draws a filled rectangle –extends AbstractDrawableDisplay Has an id, location, direction, color, and environment Don’t act or die

Georgia Institute of Technology Walls

Georgia Institute of Technology Other Ways to Extend Change the way things are drawn –Create new classes that extend FishDisplay like RoundFishDisplay and NarrowFishDisplay Reuse classes for Checkers Simulate a rat in a maze –Some rats can move randomly –Some rats can go toward the cheese