Download presentation
Presentation is loading. Please wait.
Published byKory Shepherd Modified over 9 years ago
1
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
2
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
3
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)
4
Analysis Use Case –List user actions and system responses for a particular subproblem (case) as they occur For the Phone Directory 1.Read directory from existing file 2.Insert new entry 3.Edit existing entry 4.Retrieve and display entry
5
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.
6
Insert New Entry / Edit Entry 1.User issues insert or edit command 2.System prompts for name 3.User enters name (If canceled, terminate) 4.System prompts for number 5.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)
7
Retrieve Entry
8
Initial Design (subproblems)
9
Class Diagram (initial)
10
Class Diagram (Revised)
11
loadData() addOrChangeEntry() lookupEntry() … > PhoneDirectoryInterface + loadData() + addOrChangeEntry() +lookupEntry() … ArrayListsBasedPD - String name - String number + getName() + getNumber() … DirectoryEntry processCommands() > PDUserInterface PDGUI PDConsole + main() PDApplication
12
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
13
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)
14
DirectoryEntry Class
15
PhoneDirectory Interface
16
ArrayBased PD implements PhoneDirectory
17
Class structure
18
Implementing and Testing the Array- Based Phone Directory
19
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
20
Controversial Code
21
Implementations of PDUserInterface PDGUI (graphical) PDConsoleUI (text-based)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.