import java.util.Arrays; import dsUtils.WordReader; public class WordFrequencyAnalyzer {     /**********************************************************************************/     /* You are not allowed to add any fields to this class beyond the one given below */     /* You may only read in from the file once.  This means you may only use a single */     /* word reader object.                                                            */     /**********************************************************************************/          // Currently, the field counters is not used.     // Your task is to make this class more efficent by storing the word counts     // as a symbol table / map / dictionary in the field counters.     private SequentialSearchST counters;          private String filename;               /**      * Stores a count of the number of times any word appears in a file.  The file is      * read in exactly once at the time time this object is constructed.      * (You need to modify the constructor to do this.)      *       * @param filename the name of the file on which to count all word occurrences.      */     public WordFrequencyAnalyzer(String filename) {         this.filename = filename;     }          /**      * Returns the number of times a given word appears in the file from which this      * object was created.      * (Currently, it reads through the entire file to count the number of times      * the given word appears.  Modify this to instead use the information stored      * in the counters field.)      *       * @param word the word to count      * @return the number of times word appears.      */     public int getCount(char[] word) {         WordReader r = new WordReader(filename);         int count = 0;         for(char[] w : r) {             if (Arrays.equals(w, word))                 count++;         }         return count;     }          /**      * Returns the maximum frequency over all words in the file from which this      * object was created.      * (Currently, this method is not implemented.  You must implement it.)      *       * @return the maximum frequency of any word in the the file.      */     public int maxCount() {         throw new RuntimeException("Not implemented.");     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

import java.util.Arrays;

import dsUtils.WordReader;

public class WordFrequencyAnalyzer {
    /**********************************************************************************/
    /* You are not allowed to add any fields to this class beyond the one given below */
    /* You may only read in from the file once.  This means you may only use a single */
    /* word reader object.                                                            */
    /**********************************************************************************/
    
    // Currently, the field counters is not used.
    // Your task is to make this class more efficent by storing the word counts
    // as a symbol table / map / dictionary in the field counters.
    private SequentialSearchST<String, Integer> counters;
    
    private String filename;
    
    
    /**
     * Stores a count of the number of times any word appears in a file.  The file is
     * read in exactly once at the time time this object is constructed.
     * (You need to modify the constructor to do this.)
     * 
     * @param filename the name of the file on which to count all word occurrences.
     */
    public WordFrequencyAnalyzer(String filename) {
        this.filename = filename;
    }
    
    /**
     * Returns the number of times a given word appears in the file from which this
     * object was created.
     * (Currently, it reads through the entire file to count the number of times
     * the given word appears.  Modify this to instead use the information stored
     * in the counters field.)
     * 
     * @param word the word to count
     * @return the number of times <code>word</code> appears.
     */
    public int getCount(char[] word) {
        WordReader r = new WordReader(filename);
        int count = 0;
        for(char[] w : r) {
            if (Arrays.equals(w, word))
                count++;
        }
        return count;
    }
    
    /**
     * Returns the maximum frequency over all words in the file from which this
     * object was created.
     * (Currently, this method is not implemented.  You must implement it.)
     * 
     * @return the maximum frequency of any word in the the file.
     */
    public int maxCount() {
        throw new RuntimeException("Not implemented.");
    }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

how/where do you insert the output? 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education