Java Reference
In-Depth Information
System.out.println(nextName + " is not in the directory.");
else
System.out.println("The phone number for " + nextName +
" is " + phoneNumber);
} // end if
nextName = getName();
} // end while
System.out.println("Bye!");
} // end main
// Returns either the name read from user, INPUT_ERROR, or QUIT.
private static Name getName()
{
Name result = null ;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter first name and last name, " +
"or quit to end: ");
String line = keyboard.nextLine();
if (line.trim().toLowerCase().equals("quit"))
result = QUIT;
else
{
String firstName = null ;
String lastName = null ;
Scanner scan = new Scanner(line);
if (scan.hasNext())
{
firstName = scan.next();
if (scan.hasNext())
lastName = scan.next();
else
result = INPUT_ERROR;
}
else
result = INPUT_ERROR;
if (result == null )
result = new Name(firstName, lastName);
} // end if
return result;
} // end getName
} // end Driver
Search WWH ::




Custom Search