// Utilities.java - Utilities to support file statistics // Author: ????? // Date: ????? // Class: CS163/CS164 // Email: ????? import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class Utilities { // Read the lines in a file into an array list public static ArrayList readLines(String infile) { ArrayList lines = new ArrayList(); try { Scanner reader = new Scanner(new File(infile)); while (reader.hasNextLine()) lines.add(reader.nextLine()); reader.close(); } catch (IOException e) { System.out.println("Cannot read: " + infile); } return lines; } // Read the tokens in a file into an array list public static ArrayList readWords(String infile) { ArrayList words = new ArrayList(); // STUDENT CODE HERE // Same as previous method except read tokens instead of lines return words; } // Count the frequency of specified character in array list public static int frequency(ArrayList strings, char match) { int frequency = 0; for (String string : strings) { for (char character : string.toCharArray()) { char lower = Character.toLowerCase(match); char upper = Character.toUpperCase(match); if (character == lower || character == upper ) frequency++; } } return frequency; } }