Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.

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

ADTs unsorted List and Sorted List
Lab 8 Ordered list. OVERVIEW In an ordered list the elements are maintained in ascending (or descending) order based on the data contained in the list.
1 SSD3 - Unit 2 Java toString & Equals Presentation Class Website:
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
CHAPTER 8 Lists. 2 A list is a linear collection Adding and removing elements in lists are not restricted by the collection structure We will examine.
1 CSCD 326 Data Structures I Stacks. 2 Data Type Stack Most basic property: last item in (most recently inserted) is first item out LIFO - last in first.
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
Chapter 7 More Lists. Chapter 7: More Lists 7.1 – Circular Linked Lists 7.2 – Doubly Linked Lists 7.3 – Linked Lists with Headers and Trailers 7.4 – A.
Topic 3 The Stack ADT.
Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
CM0551 Exam Prep. What are an algorithm’s time and space complexity? (2 marks) Answer: The growth rate of the algorithm’s time requirement and the computer.
Chapter 7 Stacks. © 2004 Pearson Addison-Wesley. All rights reserved 7-2 The Abstract Data Type: Developing an ADT During the Design of a Solution Specifications.
Goals for Today  implement a Deck of Cards  composition  Iterator interface  Iterable interface 1.
Chap. 1 Classes, Types, and Objects. How Classes Are Declared [ ] class [extends ] [implements,, … ] { // class methods and instance variable definitions.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
1 Stacks. 2 A stack has the property that the last item placed on the stack will be the first item removed Commonly referred to as last-in, first-out,
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Java Class Library: The Interface.
Chapter 4 Data Abstraction: The Walls. © 2004 Pearson Addison-Wesley. All rights reserved4-2 Abstract Data Types Modularity –Keeps the complexity of a.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 7: Characters, Strings, and the StringBuilder.
Object-Oriented Programming Simple Stack Implementation.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Overriding toString()
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
U n i v e r s i t y o f H a i l 1 ICS 202  2011 spring  Data Structures and Algorithms 
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
ITI Introduction to Computing II Lab-5 Dewan Tanvir Ahmed University of Ottawa.
CS 116 Lecture 1 John Korah Contains content provided by George Koutsogiannakis & Matt Bauer.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
114 3/30/98 CSE 143 Collection ADTs [Chapter 4] /30/98 Collection ADTs  Many standard ADTs are for collections  Data structures that manage groups.
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 5: Implementing Data Abstractions.
Chapter 2 Abstract Data Types. Chapter 2: Abstract Data Types 2.1 – Abstraction 2.2 – The StringLog ADT Specification 2.3 – Array-Based StringLog ADT.
Section 2.3 Array-Based StringLog ADT Implementation.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Chapter 5 The Queue ADT. 5.1 Queues Queue A structure in which elements are added to the rear and removed from the front; a “first in, first out” (FIFO)
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Section 2.4 Software Testing. 2.4 Software Testing The process of executing a program with data sets designed to discover errors Software testing is one.
Linked Data Structures
Sections 3.4 Formal Specification
Section 2.6 Linked List StringLog ADT Implementation
Software Development Java Classes and Methods
Lists Chapter 4.
Chapter 3: Using Methods, Classes, and Objects
Adapted from Pearson Education, Inc.
Data Abstraction David Evans cs205: engineering software
ADT list.
Chapter 9 Carrano Chapter 10 Small Java
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Chapter 9 The Priority Queue ADT
Objects with ArrayLists as Attributes
Topics OOP Review Inheritance Review Abstract Classes
Selection Sort Insertion Sort if time
Presentation transcript:

Section 2.2 The StringLog ADT Specification

2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the strings that have been inserted into it and, when presented with any given string, indicate whether or not an identical string has already been inserted. A StringLog client uses a StringLog to record strings and later check to see if a particular string has been recorded. Every StringLog must have a “name”.

StringLog Methods Constructors –A constructor creates a new instance of the ADT. It is up to the implementer of the StringLog to decide how many, and what kind, of constructors to provide. Transformers –insert(String element): assumes the StringLog is not full; adds element to the log of strings. –clear: resets the StringLog to the empty state; the StringLog retains its name.

StringLog Methods Observers –contains(String element): returns true if element is in the StringLog, false otherwise; We ignore case when comparing the strings. –size: returns the number of elements currently held in the StringLog. –isFull: returns whether or not the StringLog is full. –getName: returns the name attribute of the StringLog. –toString: returns a nicely formatted string that represents the entire contents of the StringLog.

The StringLogInterface // // StringLogInterface.java by Dale/Joyce/Weems Chapter 2 // // Interface for a class that implements a log of Strings. // A log "remembers" the elements placed into it. // // A log must have a "name". // package ch02.stringLogs; public interface StringLogInterface { void insert(String element); // Precondition: This StringLog is not full. // // Places element into this StringLog. boolean isFull(); // Returns true if this StringLog is full, otherwise returns false.

The StringLogInterface continued int size(); // Returns the number of Strings in this StringLog. boolean contains(String element); // Returns true if element is in this StringLog, // otherwise returns false. // Ignores case differences when doing string comparison. void clear(); // Makes this StringLog empty. String getName(); // Returns the name of this StringLog. String toString(); // Returns a nicely formatted string representing this StringLog. }

Application Example // // UseStringLog.java by Dale/Joyce/Weems Chapter 2 // // Simple example of the use of a StringLog. // import ch02.stringLogs.*; public class UseStringLog { public static void main(String[] args) { StringLogInterface log; log = new ArrayStringLog("Example Use"); log.insert("Elvis"); log.insert("King Louis XII"); log.insert("Captain Kirk"); System.out.println(log); System.out.println("The size of the log is " + log.size()); System.out.println("Elvis is in the log: " + log.contains("Elvis")); System.out.println("Santa is in the log: " + log.contains("Santa")); }

Output from example Log: Example Use 1. Elvis 2. King Louis XII 3. Captain Kirk The size of the log is 3 Elvis is in the log: true Santa is in the log: false

Review: the three levels Application (or user or client) level: The UseStringLog program is the application. It declares a variable log of type StringLogInterface. It uses the ArrayStringLog implementation of the StringLogInterface to perform some simple tasks. Logical (or abstract) level: StringLogInterface provides an abstract view of the StringLog ADT. It is used by the UseStringLog application and implemented by the ArrayStringLog class. Implementation (or concrete) level: The ArrayStringLog class developed in Section 2.3 provides a specific implementation of the StringLog ADT, fulfilling the contract presented by the StringLogInterface. It is used by applications such as UseStringLog. Likewise, the LinkedStringLog class (see Section 2.6) also provides an implementation.

Relationships among StringLog classes