1 / 27

CompSci 105 SS 2005 Principles of Computer Science

CompSci 105 SS 2005 Principles of Computer Science. Please try to Understand All concepts involved. Lecture 9: Implementing ADTs. Lecturer: Santokh Singh. Partitioning (Revision). ≥ p. p. <p. 0. 1. 2. 3. 4. 8. 3. 9. 1. 7. 3. 1. 7. 8. 9. 1. 3. 7. 8. 9.

sabin
Télécharger la présentation

CompSci 105 SS 2005 Principles of Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Partitioning (Revision) ≥p p <p 0 1 2 3 4 8 3 9 1 7 3 1 7 8 9 1 3 7 8 9 Textbook, pp. 83

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

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

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

  6. List ADT • Milk • Eggs • Butter • Apples • Bread • Chicken Operations? Textbook, p. 111ff

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

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

  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) } Using the ADT Operations Textbook, p. 115

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

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

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

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

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

  15. Object Oriented Programming

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

  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. A method that uses Circle public boolean isBigger( Circle A, Circle B) { if ( A.getArea() > B.getArea() ) return(true); else return(false); }

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

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

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

  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. A method that uses Circle public boolean isBigger( Circle A, Circle B) { if ( A.getArea() > B.getArea() ) return(true); else return(false); }

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

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

  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. Creating Circles Circle A = new MyCircle (); Circle B = new AreaCircle(1, 1, 2); boolean x = isBigger( A, B );

More Related