Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

ISBN: 0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

List the goals of a persuasive message.

Answered: 1 week ago

Question

Give THREE (3) suggestions on how to improve on the profitability.

Answered: 1 week ago

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago