import java.io.*; import java.util.*; public class DriverPart3{ public static ArrayList readTwitterData(String path){ ArrayList sentences = new ArrayList(); try{ //open the csv file for reading File file = new File("C:/covid_10K.csv"); BufferedReader reader = new BufferedReader(new FileReader(file)); String line = null; //loop through each line in the csv while ((line = reader.readLine()) != null){ sentences.add(SentencePart3.convertLine(line)); } }catch(Exception e){ e.printStackTrace(); } return sentences; } public static HashMap getTopWords(ArrayList sentences){ HashMap words = new HashMap(); for(int i = 0; i < sentences.size(); i++){ String[] pieces = ((SentencePart3)sentences.get(i)).splitSentence(); for(int j = 0; j < pieces.length; j++){ String word = pieces[j]; words.put(word, ((Integer)words.get(word))+1); } } return words; } public static void main(String[] args){ String path = "./covid_10K.csv"; // fill in this line with the correct path ArrayList result = readTwitterData(path); HashMap map = getTopWords(result); System.out.println("length of map: " + map.keySet().toArray().length); ArrayList results = new ArrayList(); for(int i = 0; i < map.keySet().toArray().length; i++){ int count = (Integer) map.get(map.keySet().toArray()[i]); String num = "" + count; while(num.length() < 5) num = "0" + num; results.add(num + " of "+ map.keySet().toArray()[i]); } Collections.sort(results); Collections.reverse(results); for (int i = 0; i < results.size() && i < 100; i++) System.out.println(results.get(i)); } }