Question: The code here reads in a file and converts it to a list of words. It strips out all punctuation for you. I want you

The code here reads in a file and converts it to a list of words. It strips out all punctuation for you. I want you to construct a frequency table for the words, and then print out the 100 most frequent words. Use a dictionary, a.k.a. java.util.Map. You can use TreeMap or HashMap, or if you want, try them both to see if one is faster. If you like, compare your result to the list of the 100 most common words (Links to an external site.).

Here is original program we are given:

package lab.pkg7;

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner;

public class Lab7 {

/** * @param args the command line arguments */ public static void main(String[] args) { { ArrayList words = new ArrayList<>(); try { Scanner fin = new Scanner(new File("55.txt")); while (fin.hasNext()) { String word = fin.next().toLowerCase().replaceAll("[^a-z]", "").trim(); if (word.length()>0) words.add(word); } } catch (FileNotFoundException e) { System.err.println(e); } for (int i=0; i<100; i++) System.out.println(words.get(i)); } } }

The input file is:

The Project Gutenberg EBook of The Wonderful Wizard of Oz, by L. Frank Baum

However, any input will work for this. Thanks.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!