Platform: HP Compaq 6710b
Operating System: Ubuntu 17.10
postgresql version: 9.6
openjdk version: 9
javac version: 1.8
How can I tell if a user has just pressed the Enter key? What kind of return will I get?
Are you able to post any of the code that you are working with? If so please use the code tags as mentioned here https://coderanch.com/wiki/659781/Code-Tags.
I'm pretty that you can get returned value from press Enter within Swing or AWT of JavaFX. However if you are starting with Java you may want to work you way up to that.
If you are not using Swing or AWT or JavaFX then you are most likely going to use the Scanner object.
If this is the case then I would suggest that you do something like
"Are you sure you want to continue y/n"
and then grab the next character using nextString.
You can read more about this object here https://docs.oracle.com/javase/9/docs/api/java/util/Scanner.html
The Scanner object hasn't actually got a nextString() method; it uses next() instead. Beware of nextLine(); as explained here, there is a ris of nextLine() returning an empty String if used immediately after nextAnythingElse(). I haven't seen that problem well documented anywhere, but only on this website
Sherman Willden wrote:Thank you for referring me to Scanner. I found the below code and I added the if statement and the length() statement. I wanted to know if a user just presses enter so I can let that user know that something must be entered. I think the string length let me know that.
Your if condition syntax is wrong I think. you should compare string values using .equals method like this if(string.equals(null)) or if(string.equals("")).
Campbell Ritchie wrote:The Scanner object hasn't actually got a nextString() method.
Sorry, that's what you get when you don't read the documentation all the way.
I think that this may be the better way to handle the if:
You can read about all the String class here https://docs.oracle.com/javase/9/docs/api/java/lang/String.html.
Here we're using scanner.next() to get Strings you run into a problem when you get to Address2: you can't just <enter> through the second address line if there's none. You have to use scanner.nextLine() for that.
But if you change all the next() to nextLine(), you have a problem too:
If you run this program, you skip by the first address prompt. Why? Because all the nextXxx() methods except for nextLine() leave the <enter> in the buffer (this is oversimplified, but...). nextLine() sees that <enter> and believes you just pressed the <enter> key. So the input is skipped.
So how do we fix this? One way is to "consume" the <enter> in the buffer with nextLine(), so:
Another way is to only use nextLine() and do the convertion yourself, so:
And of course, you can go back to using next() for Strings and nextInt() for integers, but you have to accept that you can't have a blank field.
This is why so many of us have written our own methods to do input from the keyboard (there's mine).
The word strlen sounds like something out of C; maybe length would be easier to understand.
You paid considerably more for 1MB of RAM in 1985 than you would for 16GB nowadays. Even allowing for inflation.
Sherman Willden wrote:. . . in 1985 . . . it was about space and memory. . . .
The sqlPokerInsert project obtains the user's input for the postgresql venue_visits database visits table values. The program then verifies that the user's inputs are valid. Upon verification, the user's inputs are inserted into the venue_visits database visits table.
The user is queried for the input with a default answer submitted by the sqlPokerInsert program. The program obtains the default answer from the config.properties file. The program obtains the sql database acceptable values from the postgresql venue_visits database tables as listed below.
cities, games, hi_lo, kills, stakes, states, v_limits, and venues.
Upon the user's values being valid, the valid entries are inserted into the venue_visits database visits table.
Just for clarity below are the venue_visits fourteen entries.
I am forcing the date and time entries into an integer by checking that the date and time are in the following formats.
Time: 1000 or 1800 or 2400 or 0200
Date: 20180213 or 20180112 or 19890811
The poker visits information I have goes back to 1989. I actually played my first $1/$5 seven-stud game at Binion's in 1968. Two striper in the USAF and part-time dining hall work at Vandenberg and saved up a whoping $60 for the game. Lost it all that night in Las Vegas and had to return to Vandyland on what I had left. It was surprising what you could do on couple of bucks and a Trailways bus.
Sounds a little complicated? It is, but the nice thing about writing separate classes for different tasks is you can concentrate on one thing, like getting the data, then work on the others later. The less each class "knows" about the others, the better. Another advantage is if you want to add a GUI later, you can.