aspose file tools*
The moose likes Beginning Java and the fly likes Program help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Program help" Watch "Program help" New topic
Author

Program help

Viviana Torres
Greenhorn

Joined: Nov 01, 2011
Posts: 6
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

Joined: Sep 08, 2007
Posts: 3071
    
  33

Please TellTheDetails


Mohamed Sanaulla | My Blog
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
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.
 
wood burning stoves
 
subject: Program help