Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a guessing game like Hangman, in which the user guesses letters, and then attempts to guess a partially hidden phrase. Display a phrase
Create a guessing game like Hangman, in which the user guesses letters, and then attempts to guess a partially hidden phrase. Display a phrase in which some of the letters are replaced by asterisk: for example, "G* T***" for "Go Team". Each time a user guesses a letter, according to the guess, either place the letter in the correct spot(s) in the phrase and display it to user or tell the user the guessed letter is not in the phrase. Display a congratulatory message when the entire correct phrase has been deduced. Save the game as Secret Phrase.java. The phrase to be guessed is selected randomly from a list of at least 10 phrases. The clue is presented to the user with asterisks replacing letters to be guessed but with space in the appropriate locations. For example, if the phrase to be guessed is No man is an island, then the user sees the following as first clue: ** *** ** ** ****** The spaces provide valuable information as where individual words start and end. Make sure that when a user makes a correct guess, all the matching letters are filled in, regardless of case. The guessing should be case-insensitive. If user enters more than 1 letters, only the first letter would be considered as the guess. At the end of round, it shows the score of users which is calculated by the length of phrase divided by the number of user's guesses. For example, if the phrase to be guessed is "The Wizard of Oz" and user have guessed it after 13 guesses, the score is 1.23 (i.e. 16/13). Obviously, user get higher score if (s)he can guess the phrase with less guesses. The following show a sample run of program (images are from left to right): Use javax.swing.JOptionPane class to have a graphical user interface (GUI) (Optional - 4 bonus marks). . Writing Java programs Problem Description Exercise 1: Use the game (Secret Phrase game) that you have developed in Assignment 4 to complete the following parts: Part A [12 marks]: The game in assignment 4 has limited appeal because each game contained only a few possible phrases to guess; after playing the games a few times, the user would have memorized all the phrases. Now modify your code by adding new method(s) in which any number of secret phrases can be saved to a text file before the game is played. Use a text editor such as Notepad to type any number of phrases into a file, one per line. Save the file as a text file such as Phrases.txt. Then, create a game that randomly selects a phrase from the file and allows the user to guess the phrase letter by letter. Part B [10 marks]: Modify the above game so that the game is composed of more than one rounds (number of rounds can be defined and set as a constant variable in the program). In each round (like part A) the program asks user to guess a new phrase. It keeps the score of users for each round which is calculated by the length of phrase divided by the number of user's guesses. When all rounds are done, the program must show the average score and a tabular report of all rounds and its related score and phrase. For example, the partial output of a run of 5 rounds is as follows: (Using GUI is optional) Round Target Phrase 1 The Wizard of Oz 2 Gone With The Wind 3 Casablanca 4 Chicago 5 Top Hat The average score is 1.23 } } public static void main(String[] args) { if (args.length == 2 || args.length == 3) { Part C [12 marks]: Use command line arguments to make your code flexible for running different parts as shown in the following main method. Score 1.23 1.64 1.25 0.88 1.17 1 final int ROUNDS = Integer.parseInt(args[0]); } else { double [] scores = new double [ROUNDS]; String [] targets = selectPhrases(ROUNDS, args); for (int i=0; i < ROUNDS; ++i) { scores[i] = runARound(targets[i]); } reportResults(targets, scores); System.out.println("Usage: java Sercet Phrase rounds [-1-f filename]"); System.out.println("rounds: a positive integer that represents the number of rounds for running program"); System.out.println("-1: randomly selects the targets from a list of phrases"); System.out.println("-f filename: randomly selects the targets from the filename"); System.exit(1); Using java Sercet Phrase 1 -1 command will execute exercise 2 in Assignment 4. Using java Sercet Phrase 1 -f filename command will execute part A of this assignment. Using java Sercet Phrase 10 -1 command will execute 10 rounds of exercise 2 in Assignment 4 in 10 and finally reports the scores detail and average score (like what is shown in part 2). However, if user runs java Sercet Phrase 5 -f filename command, the program executes 5 rounds of game where it selects its random phrases from a file named as filename. (Part B) Finally, if user tries to run the program with no argument like java Sercet Phrase the program must display the usage instruction and ends. Assume that user passes valid input as arguments of the program. (no input validation is needed) Use overloading methods to have the same task with different type of parameters so that fulfills the requirements of different parts. This makes it easy to modify your code.
Step by Step Solution
★★★★★
3.44 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
Ill provide you with a Java program that implements the Secret Phrase game as described covering all three parts of the assignment The program will us...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started