Question

Please create a Hangman game in Java language. For this game a random word will be...

Please create a Hangman game in Java language. For this game a random word will be selected from the following list (abstract, cemetery, nurse, pharmacy, climbing). You should keep a running tab of the user’s score and display it on screen; the user begins with 100 pts possible if they correctly guess the word without any mistakes. For every incorrect letter which is guessed, 10 pts should be taken away from what is left of their total possible points. For every correct letter which is guessed, their score is left unchanged. The user’s score should never be lower than 0, or exceed the mentioned points possible.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 import java.util.Scanner; <terminated > Hangmangame [Java Application] C:\Program Files\Java Its time for guess letter 3 pu

import java.util.Scanner;

public class Hangmangame {

        static String[] totalWords = { "abstract", "cemetery", "nurse", "pharmacy", "climbing" };
        static String guessString = totalWords[(int) (Math.random() * totalWords.length)];
        static String userGuessWord = new String(new char[guessString.length()])
                        .replace("\0", "_");
        static int points = 100;

        /* Main */
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                
                System.out.println("Starting with " + points + " points");
                while (points >= 0 && userGuessWord.contains("_")) {
                        System.out.println("Its time for guess letter");
                        System.out.println(userGuessWord);
                        String userGuessLetter = scan.next();
                        checkForHang(userGuessLetter);
                }
                scan.close();
        }

        /* processing user guess */
        public static void checkForHang(String userGuessLetter) {
                String tempString = "";
                for (int i = 0; i < guessString.length(); i++) {
                        if (guessString.charAt(i) == userGuessLetter.charAt(0)) {
                                tempString += userGuessLetter.charAt(0);
                        } else if (userGuessWord.charAt(i) != '_') {
                                tempString += guessString.charAt(i);
                        } else {
                                tempString += "_";
                        }
                }

                if (userGuessWord.equals(tempString)) {
                        points -= 10;
                        System.out.println("Your guess was wrong. 10 points deducted.");
                        System.out.println("Points: " + points);
                        System.out.println();
                } else {
                        userGuessWord = tempString;
                }
                if (userGuessWord.equals(guessString)) {
                        System.out.println("Amazing!! You guessed the correct one.. "
                                        + guessString);
                }
        }

}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
Please create a Hangman game in Java language. For this game a random word will be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA PROGRAMMING (Game: hangman) Write a hangman game that randomly generates a word and prompts the...

    JAVA PROGRAMMING (Game: hangman) Write a hangman game that randomly generates a word and prompts the user to guess one letter at a time, as shown in the sample run. Each letter in the word is displayed as an asterisk. When the user makes a correct guess, the actual letter is then displayed. When the user finishes a word, display the number of misses and ask the user whether to continue to play with another word. Declare an array to...

  • Hangman is a game for two or more players. One player thinks of a word, phrase...

    Hangman is a game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it by suggesting letters or numbers, within a certain number of guesses. You have to implement this game for Single Player, Where Computer (Your Program) will display a word with all characters hidden, which the player needed to be guessed. You have to maintain a dictionary of Words. One word will be selected by your program....

  • Create the game hangman using c code: Program description In the game of hangman, one player...

    Create the game hangman using c code: Program description In the game of hangman, one player picks a word, and the other player has to try to guess what the word is by selecting one letter at a time. If they select a correct letter, all occurrences of the letter are shown. If no letter shows up, they use up one of their turns. The player is allowed to use no more than 10 incorrect turns to guess what the...

  • JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The...

    JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The game chooses a random phrase from the list. This is the phrase the player tries to guess. The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation are left unhidden. So if the phrase is "Joe Programmer", the initial partially hidden phrase is: *** ********** The user guesses a letter. All occurrences of the letter in the phrase are replaced in...

  • Simple JavaScript and HTML: You'll create a simple word guessing game where the user gets infinite...

    Simple JavaScript and HTML: You'll create a simple word guessing game where the user gets infinite tries to guess the word (like Hangman without the hangman, or like Wheel of Fortune without the wheel and fortune). Create two global arrays: one to hold the letters of the word (e.g. 'F', 'O', 'X'), and one to hold the current guessed letters (e.g. it would start with '_', '_', '_' and end with 'F', 'O', 'X'). Write a function called guessLetter that...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • For this assignment, you will create a command-line version of the game Hangman. For this assignment...

    For this assignment, you will create a command-line version of the game Hangman. For this assignment you will research on StringBuilder Class (Use this link) and use it in your code. Please finish the program in Java Language Your game should have a list of at least ten phrases of your choosing (appropriate to all audiences please!) The game chooses a random phrase from the list. This is the phrase the player tries to guess. (10) ● The phrase is...

  • Create a script that presents a word-guessing game. Allow users to guess the word one letter at a...

    Create a script that presents a word-guessing game. Allow users to guess the word one letter at a time by entering a character in a form. Start by assigning a secret word to a variable. After each guess, print the word using asterisks for each remaining letter, but fill in the letters that the user guessed correctly. Store the user’s guess in a form field. For example, if the word you want users to guess is “suspicious” and the user...

  • Create a script that presents a word guessing game. Allow users to guess the word letter-by-letter by entering a character in a form. Start by assigning a secret word to a variable named $secret. Afte...

    Create a script that presents a word guessing game. Allow users to guess the word letter-by-letter by entering a character in a form. Start by assigning a secret word to a variable named $secret. After each guess, print the word using asterisks for each remaining letter but fill in the letters that the user guessed correctly. You need to store the user’s guess in a hidden text field name $hidden_guess. For example, if the word you want users to guess...

  • Write a Java program implementing a hangman game. This should be a multi file project, managed...

    Write a Java program implementing a hangman game. This should be a multi file project, managed with the directory structure discussed in class, compiled with the ant tool (using a build.xml file), and packaged as a JAR file, ready for distribution. Instructions on how to generate these files are included in our lectures. You can practice with the files ready to compile attached to Lecture 24 (the TicTacToe class example). Your project should include: 1. a text file for the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT