This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Carey Brown

Saloon Keeper
+ Follow
since Nov 19, 2001
Carey likes ...
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
Forum Moderator
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Carey Brown

Assuming that this is part of your requirements, this calls for an 'if' not a 'switch'. Do you know what the correct range is?
21 hours ago
Why do you have 1, 2, and 5 when your requirements state 3, 4, 5?
21 hours ago

Daniel Demesmaecker wrote:You can also just place the codetags first and pasted your code between them...

Nice tip. Hadn't thought of that =)
1 day ago
I see you attempted to use the Code tags. For them to work properly you must first have the code highlighted. You can do this by dragging the cursor over the code. If you have a very long block of code then sometimes this doesn't work, so an alternative way to highlight the code is to scroll up to the top of the code and single left click just before the first character, and then scroll down to the end of the code and after the last character do Shift+left click. This should now highlight the code and you can now click on the "Code" button. ALWAYS verify by clicking the "Preview" button at the bottom of the edit window.

I'll fix it for you this  time.
1 day ago
What happens if you rename the file to "" ?
2 days ago
When I google Krasomowca it shows that the 'o' is accented. Is it possible that the file name has this accent?
2 days ago
Type in
javac -version
to see what the computer thinks your version is
2 days ago
Whenever you have compile or run time errors/exceptions, post the complete error message here. There's often useful info in the message.
2 days ago
You are struggling with Scanner and how you expect console input to behave. With console input each data item must be followed by pressing the Enter key. Because Scanner was written to also deal with reading text files they are designed with the ability to put multiple values together on one line. Console input must explicitly forbid this, a task the Scanner was not designed to do.

It is also useful to create some helper methods for console input which encapsulates this concept in order to simplify your application code. Here's an example. The first two promptXXX() methods shouldn't be used but are here so that you can compare their behavior to what you are currently doing.

Note that the constant CONSOLE is created once and used everywhere. Only one Scanner built from should ever be created.
4 days ago
line 6 will leave a pending new-line. You can call nextLine() immediately after that to flush the new-line.
4 days ago
Yes, but to flush out the non-int you could call next() or nextLine(). Different behavior though.
4 days ago
It depends. If someone enters
ABC 42
Of course you want to throw away ABC, but do you also want to throw away the 42 ?
If so then call nextLine().
4 days ago
4 days ago
In you body you need to call
to flush out the non-int.
4 days ago
Your requirements don't specify whether the client or the server is responsible for the persistence of the balance. The way you've got it the client is responsible, but if the client gets closed you lose the balance unless you store it in a database or a file. If the server were to be responsible then the server should store it in a database or a file. The main difference being do you have one database (or file) per client or one for the server and therefore be able to store the balance for all users. If the server is responsible then a user id of some sort would be needed in order to retrieve the balance specific to that user.

The use of a Thread should be used regardless, the ServerSocket and accept() method are based on that model. Whether a client opens a connection once and maintains it for the life of the client, or the client re-connects for each "send" is up to you.

P.S. When you post please don't quote a previous post unless it is not obvious to which post you are referring. It just adds bulk to the thread without adding more information.
4 days ago