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

Create a Java application for the classic game \"Hangman\". APLICATION MUST LOOK

ID: 3875520 • Letter: C

Question

Create a Java application for the classic game "Hangman". APLICATION MUST LOOK EXACTLY LIKE BELOW PICTURE(S), MORE DETAILS BELOW The below pictures dictate exactly how the application/game and the user interface should look. When starting the application, user should see Screen 1. The X's indicate that a new game session has yet to be started AND the keyboard is inactive in this mode. Pressing the "Start Game" button will enable playing mode (which is what Screen 2 showcases).

Screen 1 (below):

Upon clicking Start Game, a random word no more than 16 characters long should be selected. The hyphens (-) shown below in Screen 2 represent how many characters the randomized word is. Selection of words can be any amount, so long as they meet the "no more than 16 characters" rule.

Screen 2 (below):

User will then click on letters to try and guess what the word is. Every time a letter is selected, it will count as one mark in the upper-left hand "0 tries" box, as well as display within where the letter is in the word itself. Once the word is correctly guessed (and the number of tries is also still accumululating), user can then click to the "Stop Game" button to go back to the first screen (Screen 1) and click on "Start Game". Of course, the user can stop the game at any time they choose, not only when a game is finished. Example of finished game below (Screen 3)

Welcome to Hangman L M N 0 Start Game

Explanation / Answer

import java.util.Scanner;

public class Hangman {

private static String[] words = {"terminator", "banana", "computer", "cow", "rain", "water" };

private static String word = words[(int) (Math.random() * words.length)];

private static String asterisk = new String(new char[word.length()]).replace("", "*");

private static int count = 0;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while (count < 7 && asterisk.contains("*")) {

System.out.println("Guess any letter in the word");

System.out.println(asterisk);

String guess = sc.next();

hang(guess);

}

sc.close();

}

public static void hang(String guess) {

String newasterisk = "";

for (int i = 0; i < word.length(); i++) {

if (word.charAt(i) == guess.charAt(0)) {

newasterisk += guess.charAt(0);

} else if (asterisk.charAt(i) != '*') {

newasterisk += word.charAt(i);

} else {

newasterisk += "*";

}

}

if (asterisk.equals(newasterisk)) {

count++;

hangmanImage();

} else {

asterisk = newasterisk;

}

if (asterisk.equals(word)) {

System.out.println("Correct! You win! The word was " + word);

}

}

public static void hangmanImage() {

if (count == 1) {

System.out.println("Wrong guess, try again");

System.out.println();

System.out.println();

System.out.println();

System.out.println();

System.out.println("___|___");

System.out.println();

}

if (count == 2) {

System.out.println("Wrong guess, try again");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println("___|___");

}

if (count == 3) {

System.out.println("Wrong guess, try again");

System.out.println(" ____________");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println(" | ");

System.out.println("___|___");

}

if (count == 4) {

System.out.println("Wrong guess, try again");

System.out.println(" ____________");

System.out.println(" | _|_");

System.out.println(" | / \");

System.out.println(" | | |");

System.out.println(" | \_ _/");

System.out.println(" |");

System.out.println(" |");

System.out.println(" |");

System.out.println("___|___");

}

if (count == 5) {

System.out.println("Wrong guess, try again");

System.out.println(" ____________");

System.out.println(" | _|_");

System.out.println(" | / \");

System.out.println(" | | |");

System.out.println(" | \_ _/");

System.out.println(" | |");

System.out.println(" | |");

System.out.println(" |");

System.out.println("___|___");

}

if (count == 6) {

System.out.println("Wrong guess, try again");

System.out.println(" ____________");

System.out.println(" | _|_");

System.out.println(" | / \");

System.out.println(" | | |");

System.out.println(" | \_ _/");

System.out.println(" | |");

System.out.println(" | |");

System.out.println(" | / \ ");

System.out.println("___|___ / \");

}

if (count == 7) {

System.out.println("GAME OVER!");

System.out.println(" ____________");

System.out.println(" | _|_");

System.out.println(" | / \");

System.out.println(" | | |");

System.out.println(" | \_ _/");

System.out.println(" | _|_");

System.out.println(" | / | \");

System.out.println(" | / \ ");

System.out.println("___|___ / \");

System.out.println("GAME OVER! The word was " + word);

}

}

}