Java Reference
In-Depth Information
for(;;) {
System.out.println("Enter 1 to enter a new phone book entry\n"+
"Enter 2 to find the number for a name\n"+
"Enter 9 to quit.");
int what = 0; // Stores input selection
try {
what = in.readInt();
} catch(InvalidUserInputException e) {
System.out.println(e.getMessage()+"\nTry again.");
continue;
}
switch(what) {
case 1:
book.addEntry(BookEntry.readEntry());
break;
case 2:
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 " + book.getEntry(someone).getNumber());
break;
case 9:
System.out.println("Ending program.");
return;
default:
System.out.println("Invalid selection, try again.");
break;
}
}
}
}
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:
Slim
Enter surname:
Pickens
Enter the area code:
914
Enter the local code:
Search WWH ::




Custom Search