Question: Edit this cross - reference code so that it is separated into different methods and prompts for a . txt file on a cs server

Edit this cross-reference code so that it is separated into different methods and prompts for a .txt file on a cs server instead of your computer. Include an additional prompt asking for if noise words are to be included in the output.
______________________________________________
import java.io.File;
import java.io.FileNotFoundException;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class WordCrossReference {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter file name: ");
String fileName = in.nextLine(), word;
int lineNumber;
ScannerWithLineno swl = null;
TreeMap> map = new TreeMap<>();
try {
swl = new ScannerWithLineno(new File("alice30.txt"));
while (swl.hasNext()){
word = swl.next();
lineNumber = swl.getLineno();
if(!map.containsKey(word)){
map.put(word, new LinkedHashSet<>());
}
map.get(word).add(String.valueOf(lineNumber));
}
Set keys = map.keySet();
for(String key: keys){
System.out.println(key +": "+ map.get(key));
}
swl.close();
} catch (FileNotFoundException e){
e.printStackTrace();
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!