This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program is "passing over" a line? <-- Edited Question

 
Ashley Kin
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason, my program is skipping over the first prompt to the user to type in a word.
For examples, it simply goes like this:

Please type an adjective: Please type a plural noun:

Everything else works fine, it's just passing over the first line or something.
Any help is appreciated, thanks!

 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So many lessons here...

I think you have the right idea with your 'v' and 'q' options -- I think you can carry that for the 'c' option; if I do that to your current code, it looks like this (I did reformat some):

Now that this code is so short, it is easier to see a problem with it. I think you wanted to get an option, perform it, and then loop back for another option. But there's no loop there. Even though the wasn't very long, it was harder to see this before.

I do not know what you meant when you said you had trouble "initializing" for what I've called "createFile()"; the code I've replaced with that call is the following:

If I'm interpreting things correctly, it creates a PrintStream, a Scanner, and a Console that are passed into readInput; that routine reads from one file and the console and outputs to another file. Without a better understanding of why you can't put this block of code into its own routine, I am not sure how to help with that.

By the way, you are almost certainly going to have to catch some exceptions for the File constructor calls.

Is this what you were after?

rc
 
Ashley Kin
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thank you, that worked very well!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashley Kin wrote:For some reason, my program is skipping over the first prompt to the user to type in a word.


Ralph mentioned a few lessons. One I didn't see addressed is (IMHO) at least as important as the rest: Your program is doing exactly what you told it to do. It it's "skipping" something, it's because you told it to do so. If you think otherwise when you see unexpected behavior, you will end up wasting lots of time and creating much frustration for yourself. :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic