Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that plays a game where a player is asked to fill in various wor

ID: 3622362 • Letter: W

Question

Write a program that plays a game where a player is asked to fill in various words of a mostly complete story without being able to see the rest. Then the user is shown his/her story files, each of which contains "placeholder" tokens surrounded by < and >, such as:

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>.

The user is prompted to fill in each of the placeholders in the story, and then a resulting output file is created with the placeholders filled in. For example:

Input file name? story1.txt
Please enter an adjective: silly
Please enter a plural noun: socks
Please enter a noun: tree
Please enter an adjective: tiny
Please enter a place: Canada

The resulting output story would be:

One of the most silly characters in fiction is named
"Tarzan of the socks ." Tarzan was raised by a/an
tree and lives in the tiny jungle in the heart of darkest Canada.

Explanation / Answer

Since there are only 14 minutes, let me sketch the solution in Java for you: import java.util.HashMap; public class FillIn { private final String template = "one of the most characters in fiction is named "Tarzan of the ." Tarzan was raised by a/an and lives in the jungle in the heart of darkest ."; String substitute(HashMap hash) { String result = template.replace(">adjective>", hash.get(">adjective>")); result = result.replace(">plural-noun>", hash.get(">plural-noun>"; // repeat replace for the rest of the tokens. } void getUsersResponse(HashMap map) { // write you prompt routine here and fill the hash map // with the token value the user provides. // for example: // map.put("", "silly"); } public void static main() { HashMap map = new HashMap(); Fillin fillin = new FillIn(); fillin.getUsersResponse(map); String result = fillin.substitute(map); System.out.println("result = " + result); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote