import java.lang.*; import java.util.*; import java.io.*; public class WordFrequency { public static void main(String[] args) { } // prompts the user for input, and returns it public static String getInput(String prompt) { Scanner s = new Scanner(System.in); System.out.print(prompt); String input = s.next(); return input; } // given a file name, returns a scanner for that file public static Scanner openFile(String filename) { Scanner x = null; // look at chapter 6.6 to learn about try/catch // statements and exceptions try { x = new Scanner(new File(filename)); } catch (Exception e) { System.out.println("Failed to open " + filename + ": " + e); System.exit(-1); // terminates the program } return x; } // given a file name, opens the file, and returns // PrintStream to it public static PrintStream writeFile(String filename) { PrintStream output = null; // look at chapter 6.6 to learn about try/catch // statements and exceptions try { output = new PrintStream(new File(filename)); } catch (Exception e) { System.out.println("Failed to open " + filename + ": " + e); System.exit(-1); // terminates the program } return output; } }