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 words = new ArrayCollection(CAPACITY);

// 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);

}

}

}

//--------------------------------------------------------------------------- // VocabularyDensity.java by Dale/Joyce/Weems Chapter 5 // // Displays the number

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 text

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!