Presentation is loading. Please wait.

Presentation is loading. Please wait.

ACM/JETT Workshop - August 4-5, 2005 1 Marine Biology Case Study (MBCS) A Discussion.

Similar presentations


Presentation on theme: "ACM/JETT Workshop - August 4-5, 2005 1 Marine Biology Case Study (MBCS) A Discussion."— Presentation transcript:

1 ACM/JETT Workshop - August 4-5, 2005 1 Marine Biology Case Study (MBCS) A Discussion

2 ACM/JETT Workshop - August 4-5, 2005 2 Marine Biology Case Study Simulation Program We are now ready to study the design and the core concepts used in the implementation of MBCS. The lectures in the last two days have covered most of the concepts used in this program. Because of time constraints, I will highlight the areas in this simulation study where the concepts were used.

3 ACM/JETT Workshop - August 4-5, 2005 3 MBCS – What is it? The Advanced Placement® Marine Biology Simulation case study is a Simulation program Designed to help marine biologists study fish movement in a small, bounded environment such as a lake or bay.

4 ACM/JETT Workshop - August 4-5, 2005 4 MBCS – Concepts Used In this simulation program, a number of concepts that we covered in the lectures were used. I will list some of them. Classes with multiple constructors Classes with access methods Inheritance Abstract classes Interfaces Composition (containment) using Arrays, ArrayLists Comparing objects using equals() Exceptions Graphic User Interface

5 ACM/JETT Workshop - August 4-5, 2005 5 MBCS Class diagram Let us see an UML class diagram showing the most important classes and interfaces in MBCS.

6 ACM/JETT Workshop - August 4-5, 2005 6 MBCS Class Diagram with the core classes

7 ACM/JETT Workshop - August 4-5, 2005 7 Details We will now take a detailed look at how the concepts were used in the code.

8 ACM/JETT Workshop - August 4-5, 2005 8 Use of interfaces Locatable is an interface that has a method declaration for location() which returns a Location. The interface as a contract guarantees that any object of a class that implements this interface knows its location and returns it when the location() method is called.

9 ACM/JETT Workshop - August 4-5, 2005 9 Use of interfaces The class Fish implements the Locatable interface. Therefore, it has to provide the code/implementation for the method, location().

10 ACM/JETT Workshop - August 4-5, 2005 10 Use of interfaces Test your understanding An instance of class Fish is also an instance of type Locatable. (True or False) Locatable locatable = new Locatable(); Will this compile? Locatable locatableOb = new Fish(); Will this compile? If a method accepts a parameter of type Locatable, you can call that method with an object of type Fish. (True or False)

11 ACM/JETT Workshop - August 4-5, 2005 11 Use of interfaces Test your understanding An instance of class Fish is also an instance of type Locatable. Locatable lOb = new Fish(); lOb.location(); Will this compile? lOb.move(); Will this compile? If not, how would you fix it? l

12 ACM/JETT Workshop - August 4-5, 2005 12 Use of inheritance Classes DarterFish and SlowFish are subclasses of Fish. Why was inheritance used? DarterFish and SlowFish are both Fish. Common properties as Fish: id, color, location, direction, how they breed and die. Important differences are how they move and the types of fish they breed. Inheritance was used to avoid repeating the code to make use of common features among the classes. Since the behavior of move() and generateChild() are different in the subclasss, overriding is used to redefine the code for these methods in DarterFish and SlowFish.

13 ACM/JETT Workshop - August 4-5, 2005 13 Use of inheritance Test your understanding Will these following statements compile? Mark Ok or not OK. Fish oneFish = new Fish(); oneFish = new DarterFish(); oneFish = new SlowFish(); Locatable lOb = oneFish; Locatable lOb2 = new DarterFish();

14 ACM/JETT Workshop - August 4-5, 2005 14 Use of inheritance Test your understanding Fish oneFish = new DarterFish(); oneFish.move(); //Is it move() in //Fish or move()in //DarterFish? // Are these statements ok? Locatable [] allObs = new Locatable[3]; allObs[0] = new Fish(); allObs[1] = new SlowFish(); allObs[2] = new DarterFish(); allObs[1].location(); allObs[0].move(); allObs[2].move();

15 ACM/JETT Workshop - August 4-5, 2005 15 Using Inheritance and Interfaces Environment is an interface. SquareEnvironment is an abstract class because it does not implement all the methods in Environment. The class BoundedEnv implements the environment as a 2-dimensional array. The class UnBoundedEnv implements the environment as an ArrayList. Why? Arrays cannot change size after they are constructed. ArrayList is a dynamic data structure that can grow and shrink.

16 ACM/JETT Workshop - August 4-5, 2005 16 Using Composition A Fish object contains an Environment object, theEnv. And an Environment object maintains a collection of Fish objects. Assume the constructor for class Fish is as follows: public Fish (Environment env){ theEnv = env; theEnv.add(this); }

17 ACM/JETT Workshop - August 4-5, 2005 17 Using Composition Test your understanding public Fish (Environment env) theEnv = env; theEnv.add(this); } From the above constructor, I can conclude the following: Mark the statements OK or NotOK. 1.Class Fish has an instance variable called theEnv. 2.The Fish object is adding itself to the Environment object, theEnv. 3.Using this constructor, I am creating an instance of a Fish: Fish myFish = new Fish (new BoundedEnv()); Will the above statement compile?

18 ACM/JETT Workshop - August 4-5, 2005 18 Demo Let us now run the simulation of MBCS.


Download ppt "ACM/JETT Workshop - August 4-5, 2005 1 Marine Biology Case Study (MBCS) A Discussion."

Similar presentations


Ads by Google