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 ;))
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.
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....
Re: hangman problem java coding
Quote:
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.
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 (*).
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
Re: hangman problem java coding
Code :
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..
Re: hangman problem java coding
Quote:
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?
Re: hangman problem java coding
i found it on the internet actually when i compile nothing happens... i dont know why ;//
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.