We start by imaging a database of book titles one common


The Problem

We start by imaging a database of book titles. One common operation in databases is highlighting search terms. For example, examine this book title :

Of Mice and Men

If we ignore common words (in this case "of" and "and"), we arrive to the keywords "mice" and "men". Given these keywords, we can highlight the search terms by capitalizing them while changing all other terms to lower case. This gives us two version of the title, by capitalizing the significant words in order :

of MICE and men
of mice and MEN

If a word appears more than once on an input line, only the first occurrence needs to be capitalized. Assuming none of its words are common, this book title :

One Fish Two Fish Red Fish Blue Fish

... would generate these highlighted versions :

ONE fish two fish red fish blue fish
one FISH two fish red fish blue fish
one fish TWO fish red fish blue fish
one fish two fish RED fish blue fish
one fish two fish red fish BLUE fish

You are to write a program that reads in all lines from a file, generates several new versions of each line with significant terms capitalized as illustrated here, and writes out the results to a file.

Files will only contain words. There will be no punctuation in the files. Every input line will have at least one word to be capitalized.

Each word on a line is to be separated by a single space. An extra space at the end of a line is permitted.

* Note that I may decide to springboard off of this assignment for your next assignment. Make sure you write clean, readable code, in case you need to use this code again!

Java Code

1. Create the class **SearchTermHighlighter**. All of your code will go into this class.

2. Create two private fields, each an ArrayList of String objects. One will hold the contents of the input file, the other will hold the contents
of the output file.

3. Create accessors for the input and output lists called **getInputFileContents** and **getOutputFileContents**. These methods should *copy* the lists and return the copy, not the field.

4. Create a constructor that takes the name of the input file in a String as the only parameter. The constructor must declare that it *throws FileNotFoundException*.

5. Add code to the constructor to open up a Scanner to parse the file.

Read in the entire file and store its contents in the appropriate ArrayList field.

If the file cannot be opened, then the FileNotFoundException should be thrown by the constructor.

Be sure to close the input file.

6. Create the method **parseContents**. It will take a list of common words in an ArrayList of String objects. It returns nothing.

7. Add code to **parseContents** so that it takes every line input data, highlights each word in turn, and stores new versions of each line following the rules in the problem description above.

8. Create the method **writeFile** that takes the name of the output file in a String as the only parameter and returns nothing.

9. Add code to **writeFile** to have it print out the processed lines containing capitalized words to a file. Like the constructor, it should throw a FileNotFoundException if the PrintWriter could not be created. Be sure to close the output file.

Do not attempt to modify file names or append any kind of directory information.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: We start by imaging a database of book titles one common
Reference No:- TGS02898580

Expected delivery within 24 Hours