Create a Java application for the classic game \"Hangman\". APLICATION MUST LOOK
ID: 3875486 • 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.
Screen 2 (below):
Welcome to Hangman L M N 0 Start GameExplanation / 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);
}
}
}