Use hasNextToken()
before each call to nextToken()
to check if there actually is a next token. At this step you have 0, 1, 2, 3,... Strings.
At this step, everything's fine if you have 3 Strings (first name, middle name, last name) and the program continues with the first token as the first name, the second token as the middle name and the third token as the last name, of course.
If on the other hand there are only two Strings at this step, you assign the middle name a random letter as you said, and you assign the first token to the first name and the second token to the last name.
From there, your program continues with
String firstInitial = ...