Programming and Problem Solving with Java

(やまだぃちぅ) #1

CASE STUDY^361


Responsibility Algorithms:The only responsibility that needs expanding is “Process en-
tries”. We must read the entries back in, prompt for and read a birthday, and write out
the Entryobject. Because we wrote the file one string per line, reading the data back in
is easy. Once we have an object of the class EntryPlus, we can write it to a new file using
ObjectOutputStream.


Get an Entry
Get Name object
Get Address object
Get Phone object

Process Entries
whilemore entries
Get an entry
Get birthday
entryPlus = new EntryPlus(Name, Address, Phone, Date)
Write entry on outFile

Class Name: PlusDriver Superclass: Subclasses:


Responsibilities Collaborations
Prepare input files BufferedReader

Prepare output files ObjectOutputStream
Process entries EntryPlus, Name, Address, Phone, Date
Close files BufferedReader ObjectOutputStream

Class Name: EntryPlus Superclass: Entry Subclasses:


Responsibilities Collaborations
Create (name, address, phone, date) Name, Address, Phone, Date

Create ( ) Name, Address, Phone, Date
Know birthday
return Date

Write to file (outfile) ObjectOutputStream

Free download pdf