Question: JAVA PROGRAMMING: Write a program that prompts the user for a word (the trigger ) and name of a text file. The program should use
JAVA PROGRAMMING:
Write a program that prompts the user for a word (the trigger) and name of a text file.
The program should use the attached Utilities class to read the text file into a List. It should then process it using only a ListIterator. Whenever the trigger word is encountered (use ignoreCase comparisons), the previous word in the document should be changed to all '*' characters. Line breaks should be maintained and do not affect the modification of the previous word. After the list is processed, use the Utilities class to print it. For example, if the trigger word was not, and the file contained
I would not could not in the rain Not in the dark Not on a train Not in a car Not in a tree I do not like them Sam you see Not in a house Not in a box Not with a mouse Not with a fox I will not eat them here or there I do not like them anywhere
The output would be I ***** not ***** not in the **** Not in the **** Not on a ***** Not in a *** Not in a tree I ** not like them Sam you *** Not in a ***** Not in a *** Not with a ***** Not with a fox I **** not eat them here or there I ** not like them anywhere
Do not use List's get method or any other means of accessing or manipulating the list except for the ListIterator. You may assume the file contains no punctuation.
The utilities is as below;
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Scanner;
public class Utilities {
public static final String DEFAULT_FILE = "sample.txt";
public static List
public static List
File f = new File(fileName); Scanner scan = new Scanner(f);
while (scan.hasNextLine()) { String l = scan.nextLine(); Scanner lineBust = new Scanner(l); while (lineBust.hasNext()) { content.add(lineBust.next()); } lineBust.close(); content.add(" "); } scan.close();
return content; }
public static void printAList(List
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
