Originally posted by Layne Lund:
It sounds like there are problems when trying to read the numeric value for salary. Everything else is Strings as far as I can tell, sot here shouldn't be any major issues there. To find out the problem, you can call the ioException() method on the Scanner and print out a diagnostic:
Try this and see if it gives any useful information. If you have any difficulty understanding the output, copy-and-paste it here and we'll help you decipher it.
Originally posted by marc weber:
My understanding is that Scanner is intended to read tokens, and by default these tokens are delimited by whitespace. My impression (from the API) is that the nextLine method is actually a way to skip past any remaining tokens on the current line, and reset to the next line. It then returns a String of everything that was skipped.
In contrast, the nextDouble method does not reset to the next line. So after calling nextDouble, when you then call nextLine, it will skip over what comes after the double (looking for another token) and assign that String to firstName.
Note that the code below prints the input. When it asks you for the salary, see what happens when you input "1234.56 fred".
So to get the code to work as you expect... After the nextDouble method is called, I think you need to call nextLine in order to reset to the next line. (Note that the return doesn't have to be assigned to anything. Simply adding a line of "input.nextLine();" should do it.)
[ February 12, 2005: Message edited by: marc weber ]