Top Banner
Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data Structures in Java v. 5.0, by Koffman & Wolfgang, Wiley © 2005
20

Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Dec 30, 2015

Download

Documents

Kory Shepherd
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Case Study: Designing A Telephone Directory Program

Ellen Walker

CPSC 201 Data Structures

Hiram College

Includes figures from Objects, Abstraction & Data Structures in Java v. 5.0, by Koffman & Wolfgang, Wiley © 2005

Page 2: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

The Problem

• Client wants to store a simple telephone directory in her computer

• Use for storage & retrieval of names & numbers

• Create from existing data file• Insert new names & numbers• Change numbers• Retrieve numbers• Save in data file

Page 3: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Requirements: Inputs & Outputs

• Inputs– File: one name & number per line– Interactive: name & number when requested

• Outputs– Name(s) & number(s) - one per line– File: complete directory in sequence (same format

as input file)

Page 4: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Analysis

• Use Case– List user actions and system responses for a

particular subproblem (case) as they occur

• For the Phone Directory1. Read directory from existing file

2. Insert new entry

3. Edit existing entry

4. Retrieve and display entry

Page 5: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Read Directory From File

• 1. User issues command to load & run directory

• 2. System starts program, initializing directory from data file. If the data file does not exist, an initially empty data file is created.

Page 6: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Insert New Entry / Edit Entry

1. User issues insert or edit command2. System prompts for name3. User enters name (If canceled, terminate)4. System prompts for number5. User enters number (If canceled, terminate)6. Directory is updated with new name/number

(user is informed whether new entry is added or entry was changed; if changed both old and new numbers are shown)

Page 7: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Retrieve Entry

Page 8: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Initial Design (subproblems)

Page 9: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Class Diagram (initial)

Page 10: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Class Diagram (Revised)

loadData()addOrChangeEntry()lookupEntry()…

<<interface>>PhoneDirectoryInterface

+ loadData()+ addOrChangeEntry()+lookupEntry()…

ArrayListsBasedPD

- String name- String number+ getName()+ getNumber() …

DirectoryEntry

processCommands()

<<interface>>PDUserInterface

PDGUI

PDConsole

+ main()PDApplication

Page 11: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

List of Classes

• PDUserInterface - interacts with the user• PDApplication - contains main, instantiates

everything else• PhoneDirectoryInterface - the interface for a

phone directory• ArrayListBasedPD - an implementation of that

interface• DirectoryEntry - a name/number pair

Page 12: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

PDApplication

• One Method, main– Create a new PhoneDirectory object– Send it a message to read the initial directory data

from a file– Create a new PDUserInterface Object– Send it a message to perform all user operations

on the PhoneDirectory object• This method will set up a loop that accepts and executes

commands (using internal methods)

Page 13: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

DirectoryEntry Class

Page 14: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

PhoneDirectory Interface

Page 15: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

ArrayBased PD implements PhoneDirectory

Page 16: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Class structure

Page 17: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Implementing and Testing the Array-Based Phone Directory

Page 18: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Implementing and Testing the Array-Based Phone Directory (continued)

• Note that some code in this application is controversial– Combination of assignment with the evaluation of

a condition– Break statement allows exiting of the while loop

without storing an entry

Page 19: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Controversial Code

Page 20: Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data.

Implementations of PDUserInterface

• PDGUI (graphical)• PDConsoleUI (text-based)