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

Java guessing game

P Derlyuk
Ranch Hand

Joined: Feb 17, 2013
Posts: 33
I am having a lot of trouble coding a java guessing game. Its from 1-100 and shows how many guesses it took to guess it right. Once you guess it right, it asks if you want to repeat. if the ans you write starts with a "y", it repeats; otherwise it prints the total games and total tries(i haven't gotten to stats yet) . Here is what i have so far...


Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7779
    
  21

P Derlyuk wrote:Here is what i have so far...

OK, so what happens when you run it? Presumably, not what you expect, so it would be useful if you could TellTheDetails (←click).

However, my general advice in cases like this is always the same: StopCoding.

Go back and write down the steps needed to play the game, in English, and see how they match up with the code you've written. You'll probably find that you can answer most of your own questions.

Just one other general observation: Your code is quite tightly coupled.
Have you considered a class that encapsulates a single run of the game? Don't worry about it too much until you get your code working, but you may find that it makes your program a lot tidier.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Daryle Foulke
Greenhorn

Joined: Aug 27, 2009
Posts: 8

What's not working as you expect? I'm not going to run your code, but I will help if you have a questions other then heres my code, whats wrong?



==============================
-Daryle
P Derlyuk
Ranch Hand

Joined: Feb 17, 2013
Posts: 33
Im having trouble defining the parameters for the method that plays one game. That method is then repeated if the user wants to with a do-while loop. Im not sure if it should only take a scanner and/or a rand.
Daryle Foulke
Greenhorn

Joined: Aug 27, 2009
Posts: 8

Have you tired compiling you program? I don't think it will even compile. I would do that first and run what you have. Are you getting the results you want?
P Derlyuk
Ranch Hand

Joined: Feb 17, 2013
Posts: 33
It compiled and ran when all the code was all in main. My instructor then specified that she wanted to play one game in a method and then repeated in main with do-while so that is what i attempted to do. I attached the code before i tried to put it in a method and repeat it. That's where i believe i screwed it up.





Daryle Foulke
Greenhorn

Joined: Aug 27, 2009
Posts: 8

Here is a little hint to get you going. Try to get it to compile as you have it first. i think that would be the best place to start. Why are you calling your playOneGame function twice? also when calling a function you dont need to define the variable types.




maybe



Give that a try and see what else you need to change. Then just play around with it until you get the results your looking for.
P Derlyuk
Ranch Hand

Joined: Feb 17, 2013
Posts: 33
Thanks! That was my method problem. I'm working on the program so it prints the stats when the user is finished playing. Ill write back if any other problems arise.
Thank you so much for your help so far.
P Derlyuk
Ranch Hand

Joined: Feb 17, 2013
Posts: 33
I kinda restructured the program but it works with your tips!
Thanks a bunch Daryle!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java guessing game