my dog learned polymorphism*
The moose likes Beginning Java and the fly likes I need help with a hangman project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I need help with a hangman project" Watch "I need help with a hangman project" New topic
Author

I need help with a hangman project

Jesse Schlicklin
Greenhorn

Joined: Mar 28, 2013
Posts: 9
Here's my code. I've been stressing out and have tons of questions/concerns. If somebody would be kind enough to help what through my code with me and could point me in the right direction for each class that would be great.

If we could start with the static boolean printCurrStatus(String strToGuess, String userInputs) class that would be great.

Thank you!

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Why are all the methods static?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jesse Schlicklin
Greenhorn

Joined: Mar 28, 2013
Posts: 9
Bear Bibeault wrote:Why are all the methods static?


The professor wants it done both in static and non-static.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

I have no idea what that means.
Jesse Schlicklin
Greenhorn

Joined: Mar 28, 2013
Posts: 9
Bear Bibeault wrote:I have no idea what that means.


I'm sorry he wants us to rewrite the Hangman.java program into Hangman2.java (after Hangman.java is finished), and the Hangman2.java is suppose to have all static keywords removed except for the static on the method main.


But I'm still stuck on the Hangman.java
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

OK, it is correct that only main should be static.

What specific problems are you having?
Jesse Schlicklin
Greenhorn

Joined: Mar 28, 2013
Posts: 9
Bear Bibeault wrote:OK, it is correct that only main should be static.

What specific problems are you having?


My printCurrStatus and playGame methods are not working correctly. My output is coming out "Enter a Letter", and when I enter one it's asking me to enter another one instead of printing out

Current Status for userInputs: a

_ _ _ _ _ _

Enter a Letter


I believe it has to do with my printCurrStatus not properly printing the information out.
Jesse Schlicklin
Greenhorn

Joined: Mar 28, 2013
Posts: 9
I went ahead a rewritten my code last night, but if somebody could help me figure out whats wrong with my output that would be wonderful!

My output is bolded and it's not letting ------, Letters Guessed:, and Enter next letter take its own line without being all smashed together. Also my Letters Gussed (found in printCurrStatus) is printing out the word that needs to be found. Also my -------, isn't keeping track of all the letters that were found. In my output when 'e' is found the 'a' dissapears; this also is found in (printCurrStatus).

Any help would be greatly appreciated.

Enter next letter
a
---a--- Letters Guessed: giraffeEnter next letter
d
------- Letters Guessed: giraffeEnter next letter
b
------- Letters Guessed: giraffeEnter next letter
e
------e Letters Guessed: giraffeEnter next letter
g
g Letters Guessed: giraffeEnter next letter


Jesse Schlicklin
Greenhorn

Joined: Mar 28, 2013
Posts: 9
I fixed the line seperate problem and the other two problems remain.

output:

Enter next letter:
a
_ _ _ _ _ _
Current user input : simple
Enter next letter:
d
_ _ _ _ _ _
Current user input : simple
Enter next letter:


code:

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

Jesse Schlicklin, please BeForthrightWhenCrossPostingToOtherSites <= click the link
http://www.java-forums.org/new-java/70852-hangman-problem.html


luck, db
There are no new questions, but there may be new answers.
Jesse Schlicklin
Greenhorn

Joined: Mar 28, 2013
Posts: 9


I'm sorry about that I'll make sure it's done in future posts.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7711
    
  20

Jesse Schlicklin wrote:I fixed the line seperate problem and the other two problems remain.

You know what? I reckon you should StopCoding.

First off, your program doesn't seem to be following the rules of Hangman (at least as I remember the game), because you don't appear to be storing either ALL the guesses that the user has tried or the current state of the game.

If I remember right, if the hidden word is "cubbyhole" and I enter:
1st guess: a
2nd guess: b
3rd guess: c
I should see
c _ b b _ _ _ _ _
and one stick of the hanging frame (for the bad guess), but you only ever seem to compare the word with a single letter.

My advice: Turn off your computer and write down ALL the rules of the game exactly, and in English.
Then write out the steps needed to follow those rules (also in English) - in particular, how to display the letters that have been correctly guessed so far (and I warn you, there's more than one way to do it).

HIH

Winston

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

Joined: Mar 28, 2013
Posts: 9
Winston Gutkowski wrote:
Jesse Schlicklin wrote:I fixed the line seperate problem and the other two problems remain.

You know what? I reckon you should StopCoding.

First off, your program doesn't seem to be following the rules of Hangman (at least as I remember the game), because you don't appear to be storing either ALL the guesses that the user has tried or the current state of the game.

If I remember right, if the hidden word is "cubbyhole" and I enter:
1st guess: a
2nd guess: b
3rd guess: c
I should see
c _ b b _ _ _ _ _
and one stick of the hanging frame (for the bad guess), but you only ever seem to compare the word with a single letter.

My advice: Turn off your computer and write down ALL the rules of the game exactly, and in English.
Then write out the steps needed to follow those rules (also in English) - in particular, how to display the letters that have been correctly guessed so far (and I warn you, there's more than one way to do it).

HIH

Winston


My professor doesn't actually want the 'stick' part showing because it's a intro class (his words); I would love to take your advice and most certainly will in later projects, but I'm in a time crunch on this one.
Chip Furstenau
Greenhorn

Joined: Mar 29, 2013
Posts: 4
One thing I noticed is your call to the printCurrStatus() method has your arguments reversed. In the call you have userInputs first, and in your method signature you have strToGuess first. I'm fairly new to this myself, but I think that's part of your problem.
Jesse Schlicklin
Greenhorn

Joined: Mar 28, 2013
Posts: 9
Chip Furstenau wrote:One thing I noticed is your call to the printCurrStatus() method has your arguments reversed. In the call you have userInputs first, and in your method signature you have strToGuess first. I'm fairly new to this myself, but I think that's part of your problem.


That may actually really help thanks! I've got to look at my printCurrStatus again.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7711
    
  20

Jesse Schlicklin wrote:I would love to take your advice and most certainly will in later projects, but I'm in a time crunch on this one...

I presume you've heard the story of the Tortoise and the Hare? - Well, good programmers are tortoises.

It may not seem like it right now, but the time you spend backing off and thinking about the problem will almost certainly be less than all the faffing around you're likely to have to do to get your square peg of a program to fit into its round hole.

Chip's observation is well spotted, but I don't think that simply correcting that is going to solve your problems (for all the reasons I mentioned previously).

You can't code your way out of a jam.

Winston

PS: If you post more code, please DontWriteLongLines (←click). Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I need help with a hangman project