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

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
1 CompSci 105 SS 2005 Principles of Computer Science Lecture 11: Linked Lists Lecturer: Santokh Singh Assignment 2 due tomorrow, i.e. Friday 21 Jan 2005.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
J A V A SHASHI BHUSHAN. MAIN ISSUES Object Oriented Concepts Examples FAQs.
C++ Programming Languages
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
1 Lists A List ADT Types of Lists Lists in Java Collections API Using ordered lists – Tournament Maker Using indexed lists – Josephus Problem Implementing.
CMPT 225 Abstract Data Types.
Abstract Data Types. Typical operations on data  Add data to a data collection  Remove data from a data collection  Ask questions about the data in.
Stacks. 2 Outline and Reading The Stack ADT (§2.1.1) Array-based implementation (§2.1.1) Growable array-based stack (§1.5) Java.util.Stack class Java.util.Vector.
1 Overloading vs. Overriding b Don't confuse the concepts of overloading and overriding b Overloading deals with multiple methods in the same class with.
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
Chapter 8 Objects & Classes. Definition of Object-Oriented Programming (OOP) Object-Oriented Programming (OOP) uses the analogy of real objects as a template.
Objects and Classes Object-oriented programming (OOP) revolves around – Defining classes – Creating instances of classes (objects) and interacting with.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 1: Course overview.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
The Java Collections Framework (JCF) Introduction and review 1.
CSC 212 Stacks & Queues. Announcement Many programs not compiled before submission  Several could not be compiled  Several others not tested with javadoc.
Abstract Data Types. What’s on the menu? What’s an abstract data type? How do you implement it? ADT List.
Modularity Keeps the complexity of a large program manageable by systematically controlling the interaction of its components Isolates errors Eliminates.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 3: Data Abstraction: The Walls Data Abstraction & Problem.
Midterm Review 22C:21 Computer Science II. Problem 1 A Set ADT represents some subset of {1,2,..., n} for some natural number n. It supports the operations.
1 Object-Oriented Programming Using C++ CLASS 1. 2 Review of Syllabus Catalog Description –An introduction to object oriented programming techniques using.
1 OOP : main concepts Polymorphism. 2 OOP : main concepts  The main concepts:  In a superclass –public members Accessible anywhere program has a reference.
April 24, 2017 Chapter 4 Data Abstraction The Walls
Chapter 4 Data Abstraction: The Walls. © 2004 Pearson Addison-Wesley. All rights reserved4-2 Abstract Data Types Modularity –Keeps the complexity of a.
1 CompSci 105 SS 2005 Principles of Computer Science Lecture 6: Recursion Lecturer: Santokh Singh Assignment 1 due tomorrow. Should have started working.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Superclasses and Subclasses.
CSE 143 Lecture 20 Abstract classes. 2 Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Computer Science 209 Software Development Inheritance and Composition.
29-July-2002cse Inheritance © 2002 University of Washington1 Inheritance CSE 142, Summer 2002 Computer Programming 1
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
1 Lecture 21: Binary Search Tree delete etc. operations Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
1 Object-Oriented Programming Using C++ CLASS 6. 2 Specifying ADTs: The ADT List Except for the first and last items in a list, each item has a unique.
1 Lecture 18: Selection Sort, Quicksort & Merge Sort Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
1 Inheritance and Subclasses. 2 Inheritance Often we create very similar classes –Different types of triangles: equilateral, isosceles, etc. –Different.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
1 Lecture 19: Trees Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Classes and Objects (contd.) Course Lecture Slides 19 May 2010.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
1 / 41 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 5 Programming Fundamentals using Java 1.
1 Object-Oriented Programming Using C++ CLASS 4 Honors.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Object-Oriented Programming: Polymorphism.
Implementing ArrayList Part T2 Lecture 6 School of Engineering and Computer Science, Victoria University of Wellington  Thomas Kuehne, Marcus Frean,
1 Lecture 15: Big O Notation (Wednesday) Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science Test See Web for Details Don’t be deleted!
1 Microsoft Imagine Cup
1 CS162: Introduction to Computer Science II Abstract Data Types.
Sections 3.4 Formal Specification
Lists A List ADT Types of Lists Using ordered lists – Tournament Maker
Abstract Data Types (ADT)
Stacks.
Data Abstraction A technique for increasing the modularity of a program The need to support several operations on the data arise need to define abstract.
Lecture 2: Implementing ArrayIntList reading:
Building Java Programs
Ch. 4 Data Abstraction Modular programming Procedural abstraction
Building Java Programs
Abstract Data Types (ADT)
Lecture 2: Implementing ArrayIntList reading:
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
Abstract Data Types Stacks CSCI 240
Presentation transcript:

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

2 Partitioning (Revision) <p p ≥p≥p Textbook, pp

3 Built-in Data Types int x = 14;

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

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

6 List ADT 1.Milk 2.Eggs 3.Butter 4.Apples 5.Bread 6.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 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 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 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 Program that uses the DropBox Dropbox ADT Implementation DropBox ADT Operations

13 Combining ADTs Program that uses the DropBox Dropbox ADT Implementation DropBox ADT Operations List ADT Implementation 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 );