Create a guessing game like Hangman, in which the user guesses letters, and then attempts to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
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... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
D E Factor the expression. 4x-16x+15.
-
Create a simple guessing game, similar to 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...
-
You created a Secret Phrase game similar to Hangman, in which the user guesses letters in a partially hidden phrase in an attempt to determine the complete phrase. Modify the program so that: The...
-
In what significant way do financial audits in government and not-for-profit organizations differ from those carried on in businesses? Your answer should also address the purpose of performance...
-
Carboxylic acids having a second carbonyl group two atoms away lose CO2 (decarboxylate.) through an intermediate enolate ion when treated with base. Write the mechanism of this decarboxylation...
-
What product would be obtained from hydroboration-oxidation of the following alkenes? a. 2-methyl-2-butene b. 1-methylcyclohexene
-
Assume that you are the dean of a business school and that you want your school to offer additional entrepreneurship courses. Surprisingly to you, some professors are resisting the idea of doing this...
-
Original activity-based costing, activity-based management (Adapted from CMA, June 1992) Alaire Corporation manufactures several different types of printed-circuit boards; however, two of the boards...
-
4.Indicate, by clicking on the relevant boxes, whether the following statements are true or false in relation to business valuation. The earnings yield method and the dividend growth model should...
-
The information provided in this project allows you to set up the General, Payables, and Receivables ledgers for an Ontario company named CHRIS'S WELDING, owned and run by Chris George, a master...
-
Four professors are running for chair of the Natural Science Division: Professors Darwin (D), Einstein (E), Freud (F), and Hawking (H). The votes of the professors in the natural science division are...
-
Provide a listIterator method for the ArrayList implementation in Section 16.2.3. Your method should return an object of a class implementing java.util.ListIterator. Also have the ArrayList class...
-
Show that the introduction of the size method in Exercise E16.6 does not affect the big-Oh efficiency of the other list operations. Data from exercise E16.6 Add an instance variable currentSize to...
-
Assume that a BankAccount class has methods for yielding the account owners name and the current balance. Write a function that, given a list of bank accounts, produces a map that associates owner...
-
Design an algorithm for deciding whether two binary trees have the same shape. What is the running time of your algorithm?
-
Write a method that reverses all lines in a file. Read all lines, reverse each line, and write the result.
-
The following operations are performed on a software-implementedstack: PUSH A, PUSH B, POP, PUSH C, PUSH D, POP, PUSH E, POP, POP, PUSHF a. What does the stack contain after the PUSH F? (To get...
-
Find the equations of the ellipses satisfying the given conditions. The center of each is at the origin. Passes through (2, 2) and (1, 4)
-
What does the following program segment output? for(f = 0; f < 3; ++f) for(g = 0; g < 2; ++g) System.out.print(f + " " + g + " "); a. 0 0 0 1 1 0 1 1 2 0 2 1 b. 0 1 0 2 0 3 1 1 1 2 1 3 c. 0 1 0 2 1 1...
-
Envisioning program components as objects that are similar to concrete objects in the real world is the hallmark of ____________. a. Command-line operating systems b. Procedural programming c....
-
a. Create a class named BloodData that includes fields that hold a blood type (the four blood types are O, A, B, and AB) and an Rh factor (the factors are 1 and ). Create a default constructor that...
-
Financial items for George Karatsis IT Services on 31 May 2024 are presented below in alphabetical order. Required (a) Prepare a statement of financial position similar to the one in figure 2.2. (b)...
-
Rebecca Tallance operates a rent a dress business from her home. She keeps her accounting records for business activities completely separate from her records for personal activities. At 30 June...
-
During the year ended 30 June 2024, Skilled Services, a provider of temporary secretary personnel, had collected receipts from clients for a total value of \($250000.\) Wages of \($136000\) had been...
Study smarter with the SolutionInn App