import java.io.IOException; import java.util.ArrayList; import javax.swing.JOptionPane; import javax.swing.JTextArea; import javax.swing.JScrollPane; import java.awt.Font; import java.io.File; import java.util.Scanner; public class WordsExercise { public WordsExercise() throws IOException { ArrayList theWords = new ArrayList(); String fileName = JOptionPane.showInputDialog("Enter Input File Name","src/WordsExercise.java"); // modify code here to handle the case when the user clicks cancel Scanner fileScanner = new Scanner(new File(fileName)); // the delimiters are any number of spaces,commas,periods or end-of-lines fileScanner.useDelimiter("[^a-zA-Z]+"); while( fileScanner.hasNext() ) { String nextWord = fileScanner.next(); // add code here to add the next word to // the ArrayList theWords if not already there } // end while String out = "The unique \"words\" are:\n\n"; // iterate through theWords and concatenate each word to // out along with an end-of-line character JTextArea outArea = new JTextArea(out,20,35); outArea.setFont(new Font("monospaced",Font.PLAIN,15)); JOptionPane.showMessageDialog(null,new JScrollPane(outArea)); } // end WordExercise() public static void main(String[] a) throws IOException { new WordsExercise(); } // end main } // end WordsExercise