• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program help

 
Viviana Torres
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm lost at where to even start... What I'm supposed to do is prompt the user for their name, then prompt them to guess a color. I continue prompting them until they guess "red" OR until they have run out of guesses (they get 5 guesses total). Any help is GREATLY appreciated!! This is how it's supposed to output:

Example 1:
What is your name? Bill
What color do you guess? White
let’s try again: What color do you guess? red
“Congratulations! You guessed the correct color in 2 tries.”

Example 2:
What is your name? Bill
What color do you guess? White
let’s try again: What color do you guess? Blue
let’s try again: What color do you guess? Green
let’s try again: What color do you guess? Yellow
let’s try again: What color do you guess? Violet
“Bill, you ran out of guesses, sorry!”


Here is what my code looks like, so far:

 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please TellTheDetails
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what problem are you having? Does this compile? Does it run? Does it blow up and turn your computer into a smoking pile of rubble?

it's virtually impossible to help you without knowing what kind of help you need.
 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will get you a little closer.


We clean things up a little by getting the code out of main().
Private method for determining the text the user is prompted with.
Note that the inputreader is moved up to the object level so it can be used from multiple methods, and we set it up in the constructor.
Note that it is not actually checking how the user exits the while-loop, that is, by getting the correct color versus by exceeding MAX_GUESSES. It just checks whether the last guess made was the correct one.
The two prompt strings should also be made static so they do not belong to the object but to the class.
The duplication of "red" etc on lines 29 and 33 should be eliminated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic