import java.util.*; import java.io.*; public class LinkedMain { public static void main (String[ ] args) { List aList = new LinkedList(); BufferedReader keyboardReader = new BufferedReader (new InputStreamReader (System.in)), fileReader; String inFilePath, line, word; try { System.out.print ("\n\nPlease enter the path for the input file: "); inFilePath = keyboardReader.readLine(); fileReader = new BufferedReader (new FileReader (inFilePath)); while (true) { line = fileReader.readLine(); if (line == null) break; aList.add (line); } // while not end of file fileReader.close(); System.out.print ("\nPlease enter the word you want to search for: "); word = keyboardReader.readLine(); if (aList.indexOf (word) >= 0) System.out.println (word + " was found.\n\n"); else System.out.println (word + " was not found.\n\n"); System.out.print ("Please enter the word you want to remove: "); word = keyboardReader.readLine(); int removalCount = 0; ListIterator itr = aList.listIterator(); while (itr.hasNext()) if (itr.next().equals (word)) { itr.remove(); removalCount++; } // if another instance of word has been discovered if (removalCount == 0) System.out.println (word + " was not found, so not removed.\n\n"); else if (removalCount == 1) System.out.println ("The only instance of " + word + " was removed.\n\n"); else System.out.println ("All " + removalCount + " instances of " + word + " were removed.\n\n"); System.out.print ("Please enter the word you want to append: "); word = keyboardReader.readLine(); aList.add (word); System.out.println (word + " was appended.\n\n"); System.out.print("Please enter the word you want to convert to upper case: "); word = keyboardReader.readLine(); String currentWord; boolean found = false; itr = aList.listIterator(); while (itr.hasNext() && !found) { currentWord = itr.next(); if (word.equals (currentWord)) { itr.set (word.toUpperCase()); System.out.println (word + " was converted to upper case.\n\n"); found = true; } // found word to convert to upper case } // while if (!found) System.out.println (word + " was not found, so not upper-cased.\n\n"); System.out.println ("Here is the final version:\n" + aList); } // try catch (IOException e) { System.out.println (e); } // catch } // method main } // class LinkedMain