User`s manual
Example – Creating and Using a Phone Book
5-77
Case 2 calls pb_add, which prompts the user for a new entry and then adds it
to the phone book.
case '2',
pb_add(pb_htable);
Case 3 uses input to prompt for the name of an entry to remove. If a name has
not been entered, it calls
disp to display an error message. If a name has been
input, it passes it to
pb_remove.
case '3',
name=input('Enter the name of the entry to remove: ', 's');
if isempty(name)
disp 'No name entered'
else
pb_remove(pb_htable, name);
end;
Case 4 uses input to prompt for the name of an entry to change. If a name has
not been entered, it calls
disp to display an error message. If a name has been
input, it passes it to
pb_change.
case '4',
name=input('Enter the name of the entry to change: ', 's');
if isempty(name)
disp 'No name entered'
else
pb_change(pb_htable, name);
end;
Case 5 calls pb_listall to display all entries.
case '5',
pb_listall(pb_htable);
8. Exit by Creating an Output Stream and Saving the Phone Book
If the user has selected case 6 to exit the program, a try statement calls the
constructor for a
FileOuputStream object, passing it the name of the phone
book. If the constructor fails, the
catch statement displays an error message.
If the object is created, the next statement saves the phone book data by calling
save on the Properties object pb_htable, passing the FileOutputStream