Java Reference
In-Depth Information
someone = Person.readPerson();
BookEntry entry = book.getEntry(someone);
if(entry == null) {
System.out.println(
"The number for " + someone + " was not
found.");
} else {
System.out.println(
"The number for " + someone + " is " +
entry.getNumber());
}
break;
case 9:
System.out.println("Ending program.");
return;
default:
System.out.println("Invalid selection, try again.");
break;
}
}
}
}
Directory "TryPhoneBook 1"
You're using the FormattedInput class that you developed in Chapter 8 to read the input values, so copy
the source file for this class along with the source file for the InvalidUserInputException class, which
is also from Chapter 8, to the directory for this example.
This is what the example produces with my input:
Enter 1 to enter a new phone book entry
Enter 2 to find the number for a name
Enter 9 to quit.
1
Enter first name: Algernon
Enter surname: Lickspittle
Enter area code: 914
Enter local code: 321
Enter the number: 3333
Enter 1 to enter a new phone book entry
Enter 2 to find the number for a name
Enter 9 to quit.
2
Enter first name: Algernon
Enter surname: Lickspittle
The number for Algernon Lickspittle is 914 321 3333
Enter 1 to enter a new phone book entry
Enter 2 to find the number for a name
Enter 9 to quit.
9
Ending program.
Search WWH ::




Custom Search