my program now ALWAYS writes out the println in default,
Norm Radder wrote:
my program now ALWAYS writes out the println in default,
Be sure to print out the value of choice in the error message so you can see why default was called.
Norm Radder wrote:Add the variable: choice to the print statement on line 28 so you can see its value.
An error occurred, try again! choice=<
Norm Radder wrote:
An error occurred, try again! choice=<
That shows that the contents of choice was empty. There was no value for the switch statement to use.
Check the code to see how choice can not have a value.
Carey Brown wrote:Where are you setting "scan" variable? What scan method are you calling prior to calling runCommand()?
I think we need to see more code.
Stephan van Hulst wrote:I believe the problem is caused because registerDog() uses scan.nextDouble() to read a weight, but that statement will block until you've hit enter. After you hit enter, it will read the weight from the line you entered, but the scanner won't proceed past the newline that's still in the input when you hit enter. It processes that newline when reach nextLine() in your loop, which doesn't have any characters preceding it. The solution is to call nextLine() after you've read the age from the input, and call it again after you've read the weight from the input.