Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi! So I'm trying to figure this question out, but I'm not sure what to write for the code. Thanks. (this is in java) Now

Hi! So I'm trying to figure this question out, but I'm not sure what to write for the code. Thanks. (this is in java)

Now we have every placeholder in the template, each corresponding replacement, and a way to replace a given placeholder with a given replacement. Great job so far!

Now its time to put all the pieces together. In this challenge you will generate the final Mad Lib by replacing each placeholder in the placeholder ArrayList with each corresponding replacement in the replacement ArrayList.

Output the final Mad Lib to the user once it is generated.

You may find it helpful to implement the following method:

/** * Asks the user to input replacement Strings * for each placeholder in the template. * Replaces each placeholder with the corresponding replacement. * Returns the resulting Madlib. */ private String replaceAllPlaceholders(String template)

Make sure your final program is robust. Make sure it can handle incorrect input without breaking. How does your program deal with a malformed madlib.txt template? A template with no placeholders? A template with only placeholders? Think about other edge cases you might need to account for.

Mad Libs

Here's what there is so far.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

M la !!!! FILES 1 import java.io.*; 2 import java.nio.charset. Standardcharsets; 3 import java.nio.file.Files; 4 import java.nio.file.Paths; 5 6 // This is the MadLibFileReader class 7 // It reads in a madlib text file and converts it into a Java String 8 // Feel free to explore this code, it uses the Java Files class 9 // to read in a Mad Lib template from the "madlib.txt" file. // DO NOT CHANGE THIS CODE, the program may not work if you do. public class MadLibFileReader 12 - { private static final String FILENAME "madlib.txt"; MadLibFileReader.java madlib.txt D MadLib.java 10 11 13 14 15 private String template; public MadLibFileReader() { template = loadTemplate(FILENAME); } 16 17 18- 19 20 21 22 23- 24 25 26 27 public String getMadLibTemplate() { return template; }

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions