Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: hangman problem java coding

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hangman problem java coding

    well, i have this question ->to write a simple hangman games where user A enters a phrase to guess. Then the program should display the phrase where characters are changed to *. Eg. "hello" is displayed "*****"
    Then user B has to enter 5 valid consonants, eg. h,l and a single VALID vowel eg. o

    the program should then display the phrase with the guessed characters, eg.
    h*llo
    i have to write its code in java
    i would be grateful if someone could help me about this
    thanks alot


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: hangman problem java coding

    What questions do you have about your project?
    The String class's methods will be useful.

    Start by making a list of the steps the program must take and then look at what java classes will be needed for each step and then write the code for a step, compile it and execute it to test it. Use calls to the println method to print out the values of variables to check that the code is working correctly.
    When the code for the step works, move to the next step.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hangman problem java coding

    i only have to write the coding but unfortunately i do not have any idea about how could i start....

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: hangman problem java coding

    idea about how could i start....
    I guess we crossed in posting:

    Start by making a list of the steps the program must take and then look at what java classes will be needed for each step and then write the code for a step, compile it and execute it to test it. Use calls to the println method to print out the values of variables to check that the code is working correctly.
    When the code for the step works, move to the next step.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hangman problem java coding

    but my main problem is how can i use a loop to give player B 5 chances to enter 5 consonants and these consonants are substituted with the asterics .

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: hangman problem java coding

    Save that type of detail until you have all the other details worked out.
    Or if you want to work on this part of the program, do as I suggested earlier:
    Make a list of the steps the code must do to solve that problem. Break the problem down into separate steps. For example:
    loop 5 times
    test for consonant
    substitute for *
    etc
    and then work on solving each step one at a time
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hangman problem java coding

    public class hangman {
    	public static void main(String args []){
     
     
     
     
     
     
     
    		   Scanner input  = new Scanner(System.in);
    		   String yes = "Hello World";
    		   String g = "";
    		   for (int i = 0; i < yes.length(); ++i) g += '*';
    		   while (yes.equals(g)) {
    		       String resp = input.next();
    		       String temp = "";
    		       for (int i = 0; i < yes.length(); ++i) {
    		           if (g.charAt(i) == '*' && yes.charAt(i) == resp.charAt(0))
    		              temp += resp.charAt(0);
    		           else
    		              temp += g.charAt(i);
    		       }
     
     
     
     
     
     
    		   }
         }
    }
    could you please tell me in brief what this program do? i think im close to the code i need .
    sorry asking alot but im very bad at java..
    Last edited by Norm; January 8th, 2013 at 12:45 PM. Reason: added code tags

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: hangman problem java coding

    tell me in brief what this program do
    Where did you get that code? It's a strange question if you wrote it.

    Which line(s) do you have questions about?

    What happens when you compile and execute the program?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hangman problem java coding

    i found it on the internet actually when i compile nothing happens... i dont know why ;//

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: hangman problem java coding

    Go back to what I suggested earlier. Make a list of the steps the program needs to do and work on them one at a time. Trying to rewrite someone else's code that you don't understand can make for confusion and frustration.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. For Loop and String Problem - Console Hangman Game
    By ashboi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 29th, 2012, 12:15 AM
  2. Java Hangman!
    By JavaManNoob in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 28th, 2012, 11:17 PM
  3. Help with Java coding problem!
    By eyesackery in forum Java Theory & Questions
    Replies: 4
    Last Post: June 4th, 2012, 08:21 AM
  4. Coding Problem
    By BohmfalkCW in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 26th, 2012, 06:10 PM
  5. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM