• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

User input does nothing

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic