Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
I am having a great deal of frustration trying to use the scanner to get user input from the eclipse console.
Here is what I am trying to do.
Print a menu for the user with options, take that (1) char input and run it into a switch statement for processing.
I have that done and it is working fine.
If the user chooses to enter strings for storage, They are instructed to enter their string and press enter to complete that string entry.
Then enter the next string and press enter, etc.
So I have a While loop for this. Get the scanner input, store it in the LinkedList, get the next scanner input, etc.
I get the scanner string and store it in a Linked list. That works fine.
The user is instructed to simply enter a blank string to end the entry procedure, like just press Enter on the new line without typing a new string.
The problem is the scanner doesn't seem to return anything for me to Test to close this procedure.
How do I TRAP the fact that the user just pressed enter so I can end my procedure?
I have tried next() and nextLine() and reset(), etc. And I am getting knowhere.
At this point you start getting confused. You would like to use a Scanner#nextChar method but there is no such thing, even though there seem to be lots of Scanner#nextXXX methods. I think the idea was that a Scanner divides input into “tokens” and you can't necessarily have a char as a token. The nearest you can get to that is to usemyScanner.next()to get the next token and then it is a String. Remember Strings have a method which gives you the char at a particular location. Remember that String indices are related to array indices, so they start at 0. Unless you do something silly with your Scanner, you cannot get an empty String from Scanner#next, so every token you get will have a “first” character.