Skip Top Navigation Bar

Spoiler Alert Lab

Stop giving away who the hero is at the end of the movie or your favorite book, or the final boss in a game. Write a program to hide a selected word or phrase from text so that it doesn't ruin the plot or twists in books, movies or games.

Your Mission

Write a program to modify the description of a book, movie, or game to avoid revealing spoilers. Your program will replace all occurrences of a given word with a number of asterisks equal to the length of the word or phrase being replaced.

Example 1

Book Description: "The dragon wins! Beware the dragon!" Spoiler Word: "dragon"

Final Description: "The ****** wins! Beware the ******!"

Determine Test Cases

Develop test cases to check to see if your code works properly. Be sure to have a test case for each of the following scenarios:

Algorithm

Write your algorithm for this program.

Trace Your Algorithm

Use your test cases to trace through your algorithms and make necessary adjustments.

Write Your Program in the Java Playground

Input for this program is optional, so you can write your code in the Java playground.

Using Input? Use an IDE

Now that you have planned out your program, it's time to write it in your IDE. Since this program requires input values, use of the Java Playground is not an option.

Create a SpoilerAlert.java file for your main program file. Add your algorithm to the body of the main method in the starter code provided.