Question
//--------------------------------------------------------------------------- // VocabularyDensity.java by Dale/Joyce/Weems Chapter 5 // // Displays the number of total words, unique words in the input text file, // and the
//---------------------------------------------------------------------------
// VocabularyDensity.java by Dale/Joyce/Weems Chapter 5
//
// Displays the number of total words, unique words in the input text file,
// and the resulting vocabulary density.
// Input file indicated by a command line argument.
//---------------------------------------------------------------------------
package ch05.apps;
import java.io.*;
import java.util.*;
import ch05.collections.*;
public class VocabularyDensity
{
public static void main(String[] args) throws IOException
{
final int CAPACITY = 1000; // capacity of collection
String fname = args[0]; // input file of text
String word; // current word
int numWords = 0; // total number of words
int uniqWords; // number of unique words
double density; // vocabulary density
CollectionInterface
// Set up file reading
FileReader fin = new FileReader(fname);
Scanner wordsIn = new Scanner(fin);
wordsIn.useDelimiter("[^a-zA-Z']+"); // delimiters are nonletters,'
while (wordsIn.hasNext()) // while more words to process
{
word = wordsIn.next();
word = word.toLowerCase();
if (!words.contains(word))
words.add(word);
numWords++;
}
density = (double)numWords/words.size();
System.out.println("Analyzed file " + fname);
System.out.println(" \tTotal words: " + numWords);
if (words.size() == CAPACITY)
System.out.println("\tUnique words: at least " + words.size());
else
{
System.out.println("\tUnique words: " + words.size());
System.out.printf(" \tVocabulary density: %.2f", density);
}
}
}
12. Revit the collection becomes full, then the application no longer continues 3. processing-instead it displays a suitable message and then ends. b. it includes a constant THRESHOLD of type int and ignores words whose length is less than the threshold value - thus the word analysis would not include "short" words. c. it permits multiple filenames to be passed as command line arguments, and will proceed to separately analyze and report on each of the files. d. expand on the previous revision so that in addition to the separate analysis of the files it also performs a combined analysis, as if the combined files all represented a single textStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started