Use Scanner and File to read input from a file. Use PrintStream and File to write output to a file. Write and call methods that accept parameters and return values to manage information flow and add structure to programs. Follow prescribed conventions for spacing, indentation, naming, and comments

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

 

  •  
  • Use Scanner and File to read input from a file.
  • Use PrintStream and File to write output to a file.
  • Write and call methods that accept parameters and return values to manage information flow and add structure to programs.
  • Follow prescribed conventions for spacing, indentation, naming, and comments.

Notice that if an input file is not found, either for creating a mad-lib or viewing an existing one, the user is re-prompted. No re-prompting occurs for the output file. If the output file does not already exist, it is created. If it does already exist, its contents are overwritten. (These are the default behaviors in Java.) You may assume that the output file is not the same file as the input file.

When you are viewing an existing mad lib story, you are simply reading and echoing its contents to the console. You do not need to do any kind of testing to make sure that the story came from a mad lib input file; just output the file's contents.

Menu options can be chosen in any order and are not related to each other. The user can choose to view any file, regardless of what file (if any) was just created.

Your program's menu should work properly regardless of the order or number of times its commands are chosen. For example, the user should be able to run each command (such as C or V) many times if so desired. The user should also be able to run the program again later and choose the V option without first choosing the C option on that run. The user should be able to run the program and immediately quit with the Q option if so desired. And so on.

Input Files

You will need to download the example input files from our web site and save them to the same folder as your program. Mad lib input files are mostly just plain text, but they may also contain placeholders. Placeholders are represented as input tokens that begin with < and end with >. Placeholders may also contain additional < and > characters in the text of the placeholder. For example, the file tarzan.txt used in the previous log contains:

Sample input file: tarzan.txt

One of the most <adjective> characters in fiction is named

"Tarzan of the <plural-noun> ." Tarzan was raised by a/an

<noun> and lives in the <adjective> jungle in the

heart of darkest <place> . He spends most of his time

eating <plural-noun> and swinging from tree to <noun> .

Whenever he gets angry, he beats on his chest and says,

" <funny-noise> !" This is his war cry. Tarzan always dresses in

<adjective> shorts made from the skin of a/an <noun>

and his best friend is a/an <adjective> chimpanzee named

Cheetah. He is supposed to be able to speak to elephants and

<plural-noun> . In the movies, Tarzan is played by <person's-name> .

 

You may assume that each word/token from the input file is separated by neighboring words by a single space. In other words, when you are writing the output, you may place a single space after each token to separate them. You do not need to worry about blank spaces at the end of lines of the output file. It's okay to place a space after each line's last token. Your output mad lib story must retain the original placement of the line breaks from the input story.

Placeholders

Only remove the < and > that surround a placeholder—do not remove or change other instances of < and > that may appear in the file.

Your program should break the input into lines and then into tokens using Scanner objects so that you can look for all its placeholders. Normal, non-placeholder word tokens can be written directly to the output file as-is, but placeholder tokens should cause the user to be prompted using the text inside the placeholder, with the beginning < and ending > removed. The user's response to the prompt is written to the madlib output file, rather than the placeholder itself. You should accept whatever response the user gives, even a multi-word answer or a blank answer.

Sometimes a placeholder has multiple words in it, separated by a hyphen (-), such as <proper-noun>. As your program discovers a placeholder, it should convert any such hyphens into spaces. Any hyphens that appear outside of a placeholder, such as in the other text of the story, should be retained and not converted into spaces.

When prompting the user to fill in a placeholder, give a different prompt depending on whether the text inside the placeholder begins with a vowel (a, e, i, o, or u, case-insensitively). If so, prompt for a response using "an". If not, use "a".

Placeholder Resulting Prompt
<noun> Please type a noun:
<adjective> Please type an adjective:
<plural-noun> Please type a plural noun:
<Emotional-Actor's-NAME> Please type an Emotional Actor's NAME:

 

This program requires you to process user input, which you must do using a Scanner. All console input should be read using the nextLinemethod in the Scanner class, not the next method.

All file input and output in your program should be handled with the File, Scanner, and PrintStream classes. Do not use other methods of file I/O.

"Mad Libs" are short stories that have blanks called placeholders to be filled in. In the non-computerized version of this A Make sure that th
game, one person asks a second person to fill in each of the placeholders without the second person knowing the
format and structure
your output exactly
match the given logs
overall story. Once all placeholders are filled in, the second person is shown the resulting story, often with a humorous
outcome.
In this assignment you present a menu to the user with three options: create a new mad lib, view a previously created mad lib, or quit. Th
are represented as C, V, and Q, case-insensitively. If anything else is typed, the user is re-prompted.
When creating a new mad lib, the program prompts the user for input and output file names. Then the program reads
A Menu options shc
the input file, prompting the user to fill in any placeholders that are found without showing the user the rest of the
be case-insensitive.
story. As the user fills in each placeholder, the program writes the resulting text to the output file. The user can later
unrecognized option
entered, the user sh
view the mad lib that was created or quit the program. The log below shows one sample execution of the program:
be re-prompted unti
valid option is given.
Sample program execution #1
Welcome to the game of Mad Libs.
I will ask you to provide various words
and phrases to fill in a story.
The result will be written to an output file.
(C) reate mad-lib, (V)iew mad-lib, (Q)uit? c
Input file name: oops.txt
File not found. Try again: TORZON.txt
File not found. Try again: tarzan.txt
Output file name: out1.txt
Please type an adjective: silly
Please type a plural noun: apples
Please type a noun: frisbee
Please type an adjective: hungry
Please type a place: Tacoma, WA
Please type a plural noun: bees
Please type a noun: umbrella
Please type a funny noise: burp
Please type an adjective: shiny
Please type a noun: jelly donut
Transcribed Image Text:"Mad Libs" are short stories that have blanks called placeholders to be filled in. In the non-computerized version of this A Make sure that th game, one person asks a second person to fill in each of the placeholders without the second person knowing the format and structure your output exactly match the given logs overall story. Once all placeholders are filled in, the second person is shown the resulting story, often with a humorous outcome. In this assignment you present a menu to the user with three options: create a new mad lib, view a previously created mad lib, or quit. Th are represented as C, V, and Q, case-insensitively. If anything else is typed, the user is re-prompted. When creating a new mad lib, the program prompts the user for input and output file names. Then the program reads A Menu options shc the input file, prompting the user to fill in any placeholders that are found without showing the user the rest of the be case-insensitive. story. As the user fills in each placeholder, the program writes the resulting text to the output file. The user can later unrecognized option entered, the user sh view the mad lib that was created or quit the program. The log below shows one sample execution of the program: be re-prompted unti valid option is given. Sample program execution #1 Welcome to the game of Mad Libs. I will ask you to provide various words and phrases to fill in a story. The result will be written to an output file. (C) reate mad-lib, (V)iew mad-lib, (Q)uit? c Input file name: oops.txt File not found. Try again: TORZON.txt File not found. Try again: tarzan.txt Output file name: out1.txt Please type an adjective: silly Please type a plural noun: apples Please type a noun: frisbee Please type an adjective: hungry Please type a place: Tacoma, WA Please type a plural noun: bees Please type a noun: umbrella Please type a funny noise: burp Please type an adjective: shiny Please type a noun: jelly donut
Please type an adjective: beautiful
Please type a plural noun: spoonS
Please type a person's name: Keanu Reeves
Your mad-lib has been created!
(C) reate mad-lib, (V)iew mad-lib, (Q)uit? X
(C) reate mad-lib, (V)iew mad-lib, (Q)uit? I don't understand.
(C) reate mad-lib, (V)iew mad-lib, (Q)uit? V
Input file name: OUT001.txt
File not found. Try again: i forget the file name
File not found. Try again: something.DOC
File not found. Try again: outl.txt
One of the most silly characters in fiction is named
"Tarzan of the apples ." Tarzan was raised by a/an
frisbee and lives in the hungry jungle in the
heart of darkest Tacoma, WA . He spends most of his time
eating bees and swinging from tree to umbrella .
Whenever he gets angry, he beats on his chest and says,
burp !" This is his war cry. Tarzan always dresses in
shiny shorts made from the skin of a/an jelly donut
and his best friend is a/an beautiful chimpanzee named
Cheetah. He is supposed to be able to speak to elephants and
In the movies, Tarzan is played by Keanu Reeves .
spoons
(C) reate mad-lib, (V)iew mad-lib, (Q)uit? Q
Transcribed Image Text:Please type an adjective: beautiful Please type a plural noun: spoonS Please type a person's name: Keanu Reeves Your mad-lib has been created! (C) reate mad-lib, (V)iew mad-lib, (Q)uit? X (C) reate mad-lib, (V)iew mad-lib, (Q)uit? I don't understand. (C) reate mad-lib, (V)iew mad-lib, (Q)uit? V Input file name: OUT001.txt File not found. Try again: i forget the file name File not found. Try again: something.DOC File not found. Try again: outl.txt One of the most silly characters in fiction is named "Tarzan of the apples ." Tarzan was raised by a/an frisbee and lives in the hungry jungle in the heart of darkest Tacoma, WA . He spends most of his time eating bees and swinging from tree to umbrella . Whenever he gets angry, he beats on his chest and says, burp !" This is his war cry. Tarzan always dresses in shiny shorts made from the skin of a/an jelly donut and his best friend is a/an beautiful chimpanzee named Cheetah. He is supposed to be able to speak to elephants and In the movies, Tarzan is played by Keanu Reeves . spoons (C) reate mad-lib, (V)iew mad-lib, (Q)uit? Q
Expert Solution
Introduction

Here is the detailed explanation of the program

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY