Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago