Question: Java expert please help me the program below? Here is the requirement: Here is starter code: -------- sample.txt ------------ I would not could not in
Java expert please help me the program below? Here is the requirement:
Here is starter code:
--------sample.txt------------
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
--------Utilities.java---------
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 readAFile() throws FileNotFoundException { return readAFile(DEFAULT_FILE); } public static List readAFile(String fileName) throws FileNotFoundException { ArrayList content = new ArrayList(); 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 list) { System.out.println(); for (String s: list) { System.out.print(s + " "); } System.out.println(); } }
The purpose of this exercise is to use a Listlterator to scan and edit a document. 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 Listlterator. Processing should start at the beginning of the list and proceed to the end. Whenever the trigger word is encountered use ignoreCase comparisons), the previous word in the document should be changed to a 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 do not like them anywhere The output would be not not in the Not in the Not on a A**** Not in a Not in a tree 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 not like them anywhere Do not use List's get method or any other means of accessing or manipulating the list except for the Lis erator. You may assume the file contains no punctuation. Hint: there is no sophisticated. slick tool that will do this processing. It's a brute force (ugly) program that requires the code to keep up with where the iterator is pointing. what has to be done with the iterator to find the target word, and what has to be done to reposition the iterator after Zapping the target
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
