Programming and Problem Solving with Java

(やまだぃちぅ) #1

CASE STUDY


308


Responsibility Algorithms for AddressDr: We have prepared enough files for both input
and output by now to consider these responsibilities concrete. “Process entries” implies
more than one entry, which implies a loop. Let’s instruct the user to enter “Quit” for the
first name when all of the entries have been processed.

Now all of the steps in “Process entries” are concrete.

Enter phone
Write "Enter area code: "
Read and convert area code to int
Write "Enter number: "
Read and convert number to int

Enter address
Write "Enter street address: "
Read street
Write "Enter city: "
Read city
Write "Enter state: "
Read state
Write "Enter ZIP code: "
Read zip

Enter rest of name
Write "Enter last name: "
Read last
Write "Enter middle name: "
Read middle

Process entries
Write "Quit entered for the first name ends the application."
Write "Enter first name: "
Read first
while(name is not equal to "quit")
Enter rest of name
name = new Name(first, last, middle)
Enter address
address = new Address(street, city, state, zip)
Enter phone
phone = new Phone(areaCode, number)
entry = new Entry(name, address, phone)
entry.writeToFile(outFile)
Read first
close files
Free download pdf