import java.util.Scanner;
import java.util.Random;
public class HangmanGame2
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
final String[] WordList = {
"porcupine",
"flamingo",
"sasquatch",
"poseidon",
"minnie mouse",
"mickey mouse",
"galileo"
};
String ChosenWord = WordList[(int)Math.random()*WordList.length];
StringBuffer display = new StringBuffer(ChosenWord.length());
for (int i = 0; i < ChosenWord.length(); i++)
display.append("*");
int NumberOfTries = 0;
System.out.print("Let's Begin \n\n");
System.out.println("Instructions: Enter a letter when asked. Try to guess the word in less than 6 tries or you will be a Dead Man! Good luck!\n\n");
boolean correct = false;
while (NumberOfTries < 6 && !correct)
{
String UserGuess = input.next();
String Letter = UserGuess.substring(0,1);
if (ChosenWord.indexOf(Letter) < 0)
{
System.out.printf("The letter %s does not appear anywhere in the word.\n",Letter);
NumberOfTries++;
}
else
{
if (display.indexOf(Letter) >= 0)
System.out.printf("The letter %s has already been entered as a guess.\n",Letter);
else
{
for (int p = 0; p < ChosenWord.length(); p++)
if (ChosenWord.CharAt(p)= Letter.CharAt(0))
display.setCharAt(p, Letter.CharAt(0));
}
}
correct = display.indexOf("*") < 0;
draw(NumberOfTries);
}
if (correct)
System.out.println("You have guessed " + ChosenWord + " correct and saved yourself from the gallos. Till next time that is.\n");
else
{
System.out.printf("You've had %d strikes against you. Thus you've been hung. Better luck next time.\n", NumberOfTries);
}
}
public static void draw (int num)
{
final String[] status = {
"____\n| |\n|\n|\n|",
"____\n| |\n|O\n|\n|\n|",
"____\n| |\n|O\n|/|\n|\n|",
"____\n| |\n|O\n|/|\\\n|\n|",
"____\n| |\n|O\n|/|\\\n|/\n|",
"____\n| |\n|O\n|/|\\\n|/\\\n|"
};
if (num >= 0 && num < status.length)
{
System.out.println(status(num));
}
else
{
System.out.println("Must be a Mistake. Out of Range.");
}
}
}
I currently have a couple errors still with my program. Can anyone help me figure out how to fix these? The errors are as follows and the compleate program is posted above.
HangmanGame2.java:50: error: cannot find symbol
if (ChosenWord.CharAt(p)= Letter.CharAt(0))
^
symbol: method CharAt(int)
location: variable ChosenWord of type String
HangmanGame2.java:50: error: cannot find symbol
if (ChosenWord.CharAt(p)= Letter.CharAt(0))
^
symbol: method CharAt(int)
location: variable Letter of type String
HangmanGame2.java:51: error: cannot find symbol
display.setCharAt(p, Letter.CharAt(0));
^
symbol: method CharAt(int)
location: variable Letter of type String
HangmanGame2.java:81: error: cannot find symbol
System.out.println(status(num));
^
symbol: method status(int)
location: class HangmanGame2
4 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.