Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am getting 4 errors in my Java hangman program. I can\'t figure out how to get

ID: 3532255 • Letter: I

Question

I am getting 4 errors in my Java hangman program. I can't figure out how to get rid of them. Please Help.

My Full Code:

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 ");
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! ");

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. ",Letter);
NumberOfTries++;
}

else
{
if (display.indexOf(Letter) >= 0)
System.out.printf("The letter %s has already been entered as a guess. ",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. ");

else
{
System.out.printf("You've had %d strikes against you. Thus you've been hung. Better luck next time. ", NumberOfTries);
}
}

public static void draw (int num)
{
final String[] status = {
"____ | | | | |",
"____ | | |O | | |",
"____ | | |O |/| | |",
"____ | | |O |/|\ | |",
"____ | | |O |/|\ |/ |",
"____ | | |O |/|\ |/\ |"
};

if (num >= 0 && num < status.length)
{
System.out.println(status(num));
}

else
{
System.out.println("Must be a Mistake. Out of Range.");
}
}
}

My Errors:

HangmanGame2.java:50: error: cannot find symbol

Explanation / Answer

at first glance, you have several lines where you meant to compare char with if statement, but ended up setting the elements. Use == to compare and = to set.