Question: Edit this code so that it is able to read a file from an online cs server and change the noise word checker so that
Edit this code so that it is able to read a file from an online cs server and change the noise word checker so that it uses a BST
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class WordCrossReference
public static void mainString args
Scanner in new ScannerSystemin;
System.out.printEnter the file path egpathtofiletxt: ;
String filePath innextLine;
System.out.printInclude noise words in output yesno;
boolean includeNoiseWords innextLineequalsIgnoreCaseyes;
processFilefilePath includeNoiseWords;
inclose;
private static void processFileString filePath, boolean includeNoiseWords
TreeMap map new TreeMap;
try Scanner scanner new Scannernew FilefilePath
int lineNumber ;
Read file line by line
while scannerhasNextLine
String line scanner.nextLine;
String words line.splitW; Split line into words based on nonword characters
for String word : words
if wordisEmpty continue; Skip empty words
if includeNoiseWords && isNoiseWordword
continue; Skip noise words if not included
word word.toLowerCase; Normalize to lowercase
Add word to map and record line number
map.putIfAbsentword new LinkedHashSet;
map.getwordaddlineNumber;
lineNumber; Increment line number
Print the crossreference
printCrossReferencemap;
catch FileNotFoundException e
System.err.printlnError: File not found at filePath;
private static void printCrossReferenceTreeMap map
for String key : map.keySet
System.out.printlnkey : map.getkey;
private static boolean isNoiseWordString word
Set noiseWords Set.of
"the", "and", aanoftoin "for", onat "name", "very"
;
return noiseWords.containswordtoLowerCase;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
