Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the game (Secret Phrase game) to complete the following parts: Part A : The game has limited appeal because each game contained only a

Use the game (Secret Phrase game) to complete the following parts: 

Part A : The game 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 : 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 Score
 1 The Wizard of Oz 1.23
 2 Gone With The Wind 1.64
 3 Casablanca 1.25
 4 Chicago 0.88
 5 Top Hat 1.17
The average score is 1.23

Part C : Use command line arguments to make your code flexible for running different parts as shown in the following main method.
public static void main(String[] args) {
if (args.length == 2 || args.length == 3) {
final int ROUNDS = Integer.parseInt(args[0]);
 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);
} else {
System.out.println("Usage: java SercetPhrase rounds [-l | -f filename]");
System.out.println("rounds: a positive integer that represents the
 number of rounds 

for running program");
System.out.println("-l: 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 SercetPhrase 1 -l command will execute Secret Phrase.
Using java SercetPhrase 1 -f filename command will execute part A .
Using java SercetPhrase 10 -l command will execute 10 rounds of Secret Phrase in 10 and finally reports the scores detail and average score (like what is shown in part 2). However, if user runs java SercetPhrase 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 SercetPhrase 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 functions 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. 

 

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 Score 1.23 2 Gone With The Wind 1.64 3 Casablanca 1.25 4 Chicago 5 Top Hat The average score is 1.23 0.88 1.17

Step by Step Solution

3.49 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

Complete code after PART C SecretPhrasejava import javaxswing import javaioFile import javaioFileNotFoundException import javautilArrayList import javautilRandom import javautilScanner public class Se... 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

Microeconomics

Authors: Austan Goolsbee, Steven Levitt, Chad Syverson

2nd edition

1464187029, 978-1464189104, 1464189102, 978-0716759751, 716759756, 978-1464187025

More Books

Students also viewed these Accounting questions