Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CompSci 105 SS 2005 Principles of Computer Science Lecture 9: Implementing ADTs Lecturer: Santokh Singh Please try to Understand All concepts involved.

Similar presentations


Presentation on theme: "1 CompSci 105 SS 2005 Principles of Computer Science Lecture 9: Implementing ADTs Lecturer: Santokh Singh Please try to Understand All concepts involved."— Presentation transcript:

1 1 CompSci 105 SS 2005 Principles of Computer Science Lecture 9: Implementing ADTs Lecturer: Santokh Singh Please try to Understand All concepts involved.

2 2 Partitioning (Revision) <p p ≥p≥p 93871 01234 71398 Textbook, pp. 83 731 98

3 3 Built-in Data Types int x = 14; 1110 14

4 4 Abstract Data Type A collection of data … combined with … a set of operations on that data Textbook, p. 108

5 5 The Wall Program that uses the ADT ADT Implementation ADT Operations Textbook, p. 110

6 6 List ADT 1.Milk 2.Eggs 3.Butter 4.Apples 5.Bread 6.Chicken Operations? Textbook, p. 111ff

7 7 List ADT createList() isEmpty() size() add( index, item) remove(index) removeAll() get(index) Operations Textbook, p. 113

8 8 List ADT aList.createList() aList.add(1, milk) aList.add(2, eggs) aList.add(3, butter) aList.remove(3) Using the ADT createList() isEmpty() size() add( index, item) remove(index) removeAll() get(index) Operations Textbook, p. 114

9 9 List ADT createList() isEmpty() size() add( index, item) remove(index) removeAll() get(index) for i=1 to aList.size() { data = aList.get(i) println(data) } Operations Using the ADT Textbook, p. 115

10 10 Abstract Data Types (ADTs) Examples Specifying ADTs Combining ADTs Implementing ADTs Interfaces Classes Private vs. Public Constructors Other Methods Exceptions and Inheritance

11 11 Defining ADTs What needs to be stored? What are the valid operations? Textbook, p. 119

12 12 Combining ADTs Program that uses the DropBox Dropbox ADT Implementation DropBox ADT Operations

13 13 Combining ADTs Program that uses the DropBox Dropbox ADT Implementation DropBox ADT Operations List ADT Implementation List ADT Operations

14 14 Abstract Data Types (ADTs) Examples Specifying ADTs Combining ADTs Implementing ADTs Interfaces Classes Private vs. Public Constructors Other Methods Exceptions and Inheritance

15 15 Object Oriented Programming

16 16 Circle ADT setX() setY() setRadius() getX() getY() getRadius() getArea() Operations

17 17 Java Interface public interface Circle { void setX ( float x ); void setY ( float y ); void setRadius( float r ); float getX (); float getY (); float getRadius(); float getArea (); }

18 18 A method that uses Circle public boolean isBigger(Circle A, Circle B) { if ( A.getArea() > B.getArea() ) return(true); else return(false); }

19 19 Creating Circles? Circle A = new Circle(); Circle B = new Circle(); boolean b = isBigger( A, B );

20 20 Abstract Data Types (ADTs) Examples Specifying ADTs Combining ADTs Implementing ADTs Interfaces Classes Private vs. Public Constructors Other Methods Exceptions and Inheritance

21 21 public Class MyCircle implements Circle { float x, y, radius; void setRadius( float newRadius ) { radius = newRadius; } void getArea() { return ( Math.PI * radius * radius ); }

22 22 public Class MyCircle implements Circle { // Constructors MyCircle() { x = 0.0; y = 0.0; radius = 1.0; } MyCircle(float newX, newY, newR ) { x = newX; y = newY; radius = newR; }

23 23 A method that uses Circle public boolean isBigger(Circle A, Circle B) { if ( A.getArea() > B.getArea() ) return(true); else return(false); }

24 24 Creating Circles Circle A = new MyCircle(); Circle B = new MyCircle(1, 1, 2); boolean x = isBigger( A, B );

25 25 public Class MyCircle implements Circle { : printCircle( ) { System.out.println( x, y, radius ); } :

26 26 public Class AreaCircle implements Circle { float x, y, radius, area; void setRadius( float newRadius ) { radius = newRadius; area = Math.PI * radius * radius ); } void getArea() { return ( area ); }

27 27 Creating Circles Circle A = new MyCircle (); Circle B = new AreaCircle(1, 1, 2); boolean x = isBigger( A, B );


Download ppt "1 CompSci 105 SS 2005 Principles of Computer Science Lecture 9: Implementing ADTs Lecturer: Santokh Singh Please try to Understand All concepts involved."

Similar presentations


Ads by Google