i am trying to create an interactive program that gives a prompt for the hangman game. there is meant to be a phrase book of about 100 movies. The phrase book is in an attachment. So far what i have done is made a I made a for loop to go through the length of the secret phrase and used an if/else statement to assign asterisk if the alphabet pick is right and underscore if right. Well i am not meant to use arrays so I am really stuck and i need help trying to show the correct picks and also putting a counter showing the number of wrong picks. In the end a total of wrong picks ends the game and a prompt is meant to ask if u want to replay. Thank you all for the anticipated help I am really stuck on this stuff

You are not meant to use arrays, does the restriction also imply against use of Collection like ArrayList, HashSet etc

i am trying to create an interactive program that gives a prompt for the hangman game. there is meant to be a phrase book of about 100 movies. The phrase book is in an attachment. So far what i have done is made a I made a for loop to go through the length of the secret phrase and used an if/else statement to assign asterisk if the alphabet pick is right and underscore if right. Well i am not meant to use arrays so I am really stuck and i need help trying to show the correct picks and also putting a counter showing the number of wrong picks. In the end a total of wrong picks ends the game and a prompt is meant to ask if u want to replay. Thank you all for the anticipated help I am really stuck on this stuff

Hey,

Make sure you submit your code if you have completed for those who need help in future!

Peace,

im actually working on this exact same problem, my difficulty is when you guess a letter correct i dont know how to properly reveal the letters in the secret message. here is my code

i

mport java.util.Scanner;

public class Hangman
{

    public static void main(String[] args)
    {
        intro();
        playGame();
    }
        
        public static void playGame()
        {
        PhraseBank phrases = new PhraseBank();
        String topic = phrases.getTopic();
        String wordToBeGuessed = phrases.getNextPhrase();
        String alphabet = "abcdefghijklmnopqrstuvwxyz";
        alphabet = alphabet.toUpperCase();
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Im thinking of a ");
        System.out.println(topic);
        System.out.println();
        System.out.print("The current phrase is ");
        String a = "";
        for (int i = 0; i < wordToBeGuessed.length(); i++)
            {
                char ch = wordToBeGuessed.charAt(i);
                if (ch != '_')
                {
                    a += "*";
                }
                else
                {
                    a += '_';
                }
                    
               
            }
        System.out.print(a);
        System.out.println();
        System.out.print("The letters you have not guessed yet are:");
        System.out.println();
        System.out.print(alphabet);
        System.out.println();
        
        
        int wrongGuesses = 0;
        int correctGuesses = 0;
        String b = "";
        
        while (wrongGuesses < 5)
        {
            System.out.print("Enter your next guess: ");
            String guess = keyboard.next();
            System.out.println();
            System.out.print("You guessed ");
            System.out.print(guess);
            
            if (wordToBeGuessed.indexOf(guess) >= 0)
            {
                System.out.println();
                System.out.print("That is present in the secret phrase.");
                System.out.println();
                System.out.print("You have made ");
                System.out.print(wrongGuesses);
                System.out.print(" wrong guesses");
                System.out.println();
                correctGuesses += 1;
                for (int j = 0; j < a.length(); j++)
                {
                if (wordToBeGuessed.indexOf(guess) == j)
                {
                    b += wordToBeGuessed.charAt(j);
                }
                else
                {
                if (wordToBeGuessed.charAt(j) != '_')
                {
                    b += "*";
                }
                if (wordToBeGuessed.charAt(j) == '_')
                {
                    b += "_";
                }
            }
                
                
                
            }
     
                System.out.print("The current phrase is ");
                System.out.print(b);
                System.out.println();
                
        }
            
            
            else
            {
                System.out.println();
                System.out.print("That is not present in the secret phrase.");
                wrongGuesses += 1;
                System.out.println();
                System.out.print("You have made ");
                System.out.print(wrongGuesses);
                System.out.print(" wrong guesses");
                System.out.println();
                System.out.print("The current phrase is ");
                System.out.print(b);
                System.out.println();
                
            }
            
        }       
    }

Can you please help me on doing a hangman java program because i am very close to failing my class and its my last year!! im desperate! can you please send me the code things?

The code above does not compile! it says reached end of file while parsing

Where's the intro() method located? It isn't in the hangman class or the PhraseBank class.
If it returns a reach end of file error you would need another } added to the end, most likely.

Can you please help me on doing a hangman java program because i am very close to failing my class and its my last year!! im desperate! can you please send me the code things?

If you're "in your last year" and it's not kindergarten, it's not a good sign if you can't do this yourself.
You're either terminally stupid (in which case you deserve to fail) or terminally lazy (in which case you deserve to fail), so you deserve to fail.

commented: an idiot for not knowing anything about programming? You must be the idiot making it seem like programming is life. I REALLY CANT DO IT BECAUSE I KNOW NOTHING ABOUT IT! So you either help me or just leave me alone +0

You are not meant to use arrays, does the restriction also imply against use of Collection like ArrayList, HashSet etc

Of course not. Those classes use arrays rather extensively in their implementation, therefore cannot be used.

This thread is attracting too many "gimmetehcodez" homework-kiddos. (thanks for the heads-up Jwenting)
For future reference: click me
closed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.