Question: Political-themed Hangman Game Please add on to my Java code by giving the user two options A and B, which asks how they would like
Political-themed Hangman Game
Please add on to my Java code by giving the user two options A and B, which asks how they would like to solve the puzzle. (Note: The code is supposed to already generate a random word hidden by *****, a random prize, and provide a hint to the player. Please add more code so that it gives the player A & B options after the hint is exposed.)
//Prompt player to choose A or B
Choice A prompts the player to type in the entire word/guess
1) //Prompt player to guess the entire word //A correct guess results in entire word being revealed and the output "You Win!" appears on the screen
2) //A wrong guess outputs "Guess Again" to screen, and allows player to guess again //Player should only be able to input three (3) incorrect word guesses before they encounter "Game Over" message
Choice B prompts player to guess letters in the word one by one //Prompt player to input one letter //If the letter is in the word, the letter will replace an asterisk (hidden letter) and display ///Player should only be able to input three (3) incorrect letter guesses before they encounter "Game Over" message
//Continue to ask player to input letters until entire word is revealed
//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
Get step-by-step solutions from verified subject matter experts
