• Post Reply Bookmark Topic Watch Topic
  • New Topic

User input does nothing  RSS feed

 
Ma Chan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people. I have a few problems at the moment. Below is my incomplete program. It compiles but doesn't do a whole lot when run. I am doing a project on polymophism and inheritance. I have a footwear class(parent) and sneaker & thong classes(children)...my switch statements don't do anything. I'm trying to setColour to "something"(eg: whatever option user chooses), then it is written to a file. What's going on?
 
Kathy Rogers
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem here is not an input problem. It's to do with your while clause.
Think about it like this.
If I enter 1, then choice does not equal 2 and choice does not equal 3 but it does equal 1.
So when it gets to the while clause, you get
false OR true OR true
The while clause tests the condition and finds that it's true because at least one of the sub-conditions are true - so it does the do-while loop again . . . and again . . . and again.
You only want to perform the do-while loop again only if all the conditions are true - if choice does not equal 1 AND choice does not equal 2 AND choice does not equal 3 - so try replacing those ||s with &&s or checking if choice is less than 1 or greater than 3.
Btw, in order to pick up the user input using readLine(), you have to press return after you've entered your number.
Hope this helps,
Kathy
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!