Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA For this assignment, I need to write a code that plays a game of Mad Libs with the user. It should take any Text

JAVA

For this assignment, I need to write a code that plays a game of Mad Libs with the user. It should take any Text Document as a .txt file, which includes several placeholders such as , , . It is important that the code identifies any placeholder in a text file, indicated by < and >. The user is prompted to enter in a value for the placeholder.

Example: produces output: "Please enter a school subject."

My code needs to:

1) Reprompt the user if the input file cannot be found.

2) No re-prompting occurs for the output file. If it does not already exist, it is created. If it already exists, overwrite its contents.

3) Sometimes a placeholder has multiple words in it, separated by a ( -), such as . 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.

4) When prompting the user to fill in a placeholder, give a different prompt depending on whether 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".

5) You must have at least 3 non-trivial methods other than main in your program. It is okay for some println statements and code to be in main, as long as you use good structure and main is a concise summary. Good structure matter for full credit. Repetition of code lines are not acceptable.

6) Each method should have a single purpose, and no one method should do too large a share of the overall task. The main method should not directly perform a large share of the work itself.

I have included a sample output below:

Welcome to the game of Mad Libs.

I will ask you to provide various words and phrases to fill in a story.

Input file name: story.txt

File not found. Try again: mabldib.txt

File not found. Try again: madlib.txt

Output file name: out.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: Bellevue, 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! You can access your out1.text in your C:/ directory.

Your story made out of 10 lines with 98 words.

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

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions