Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

}

}

}

image text in transcribed

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

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_2

Step: 3

blur-text-image_3

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

Students also viewed these Databases questions

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago