Question: Political-themed Hangman Game Please help finish my Java code by giving the user two options A and B, which asks how they would like to

Political-themed Hangman Game

Please help finish my Java code by giving the user two options A and B, which asks how they would like to solve the puzzle.

Choice A prompts the player to type in the entire word/guess

//Guess the word //Allow user to type up to 3 wrong guesses //Once three wrong guesses are inputted, the player loses and the game is Game Over //A correct guess however results in entire word being revealed and the output "You Win!" appears on the screen

Choice B prompts player to guess letter in the word //A loop should prompt the player to keep entering letters that display correct letters where asterisks once were until the entire word is revealed //But if the player enters three wrong letters, the player loses and the Game is Over

//Just like in Option A, correct guess however results in entire word being revealed and the output "You Win!" + cash prize value //Cash prize value = letter(num) * cashPrize . Ex: if the random prize was $10, then each correct guess of of the letter "C" in "Democratic" would win the player $20

//Begin Program

import java.util.*; import java.lang.*; import java.util.Random;

public class PolicalWordGuess { static String wordList[] = { "GOVERNMENT" , "POLITICO" , "LEGISLATURE" , "DEMOCRATIC" , "REPUBLICAN" , "SENATE" , "BIPARTISAN" , "REPUBLICAN" , "LIBERTY" , "REPRESENTATION"}; static String cashPrize[] = {"$10", "$15" , "$20" , "$25", "$30"}; static Scanner scan = new Scanner(System.in); static Random random = new Random(); static int index = random.nextInt(wordList.length); static String str1 = wordList[index]; static String results = "";

public static void main(String args[]) { System.out.println( " Word: " + str1.replaceAll("[A-Za-z0-9]", "*")); System.out.println( " Please press enter to see the prize."); scan.nextLine();

int index2 = random.nextInt(cashPrize.length);

String str2 = cashPrize[index2]; System.out.println( " Prize: " + str2); System.out.println( " Please hit press for a hint"); scan.nextLine(); for (int i = 0; i < str1.length(); i++) { if (str1.charAt(i) == 'S' || str1.charAt(i) == 's') { results = results + str1.charAt(i); } else if (str1.charAt(i) == 'T' || str1.charAt(i) == 't') { results = results + str1.charAt(i); } else if (str1.charAt(i) == 'R' || str1.charAt(i) == 'r') { results = results + str1.charAt(i); } else if (str1.charAt(i) == 'L' || str1.charAt(i) == 'l') { results = results + str1.charAt(i); } else if (str1.charAt(i) == 'N' || str1.charAt(i) == 'n') { results = results + str1.charAt(i); } else if (str1.charAt(i) == 'E' || str1.charAt(i) == 'e') { results = results + str1.charAt(i); } else if (String.valueOf(str1.charAt(i)).equals(":")) { results = results + str1.charAt(i); } else if (str1.charAt(i) == ' ' || str1.charAt(i) == ' ') { results = results + str1.charAt(i); } else { results = results + "*"; } } System.out.println(" Hint: "); System.out.println(" " + results); //Gives users two options A or B. This is the part that need to be completed. Please feel free to change anything after this point. System.out.println(" Select A) Solve the puzzle for $0 OR B) Guess a letter. You only get three guesses to solve the puzzle. Failure to solve results in Game Over! "); int choice = scan.nextInt(); if (choice == 'A') System.out.println("Please enter a letter: "); //Guess the word

if (choice == 'B') System.out.println("Please solve the puzzle: "); //Guess the letters in the word

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!