Java Reference
In-Depth Information
FIGURE 9-52
J ava 2
J ava 2
v 5 . 0
6 Maintaining a Phone Book with ArrayLists
v 5 . 0
Computers and personal digital assistant (PDA) devices help to organize many
aspects of one's life. A common application is a contact list, or phone book,
where names, phone numbers, and often much more information about friends
and business contacts is maintained.
Write a Java application to create and maintain a phone book as shown in
Figure 9-53. Users should be able to add a new contact, delete an existing con-
tact, update the phone number of an existing contact, or enter a name to find
the phone number of an existing contact. Once a contact is entered, the name
cannot be changed. Display appropriate messages when a user successfully adds,
updates, or deletes a contact. If a requested contact successfully is found in the
phone book list, display the name and phone number in the Name and Phone
number text boxes, respectively. Display appropriate error messages when any
action fails. For Java 5.0, use typesafe ArrayLists and static imports, where appro-
priate. Hint: Use two ArrayLists, one for names and one for phone numbers. For
an additional challenge, add the capability to update the name of an entry with-
out deleting the entry first.
FIGURE 9-53
7 Analysis and Design of a Reusable Tally Class
A tally is a list of different items, with a count for the number of each item. For
example, a tally of computer parts might show 12 monitors, 3 CD-ROM drives,
4 floppies, and so forth. Figure 9-54 on the next page shows a requirements
document for a reusable Tally class. Using the six phases of the development
cycle as shown in Table 9-1 on page 539, perform the steps on the next page:
Search WWH ::




Custom Search