Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I add a void method in letterTally, wordTally,sentenceTally to get the in

ID: 3720641 • Letter: H

Question

How do I add a void method in letterTally, wordTally,sentenceTally to get the information from bookMain class . and call the classes again in bookMain class, in analyzeBookText?

--------------------------------------------------------

import java.util.Scanner;
import java.io.File;

public class BookMain {
    /**
     * DO NOT MODIFY VARIABLE DECLARATIONS
     */
    LetterTally letterData;
    WordTally wordData;
    SentenceTally sentenceData;

    /**
     * DO NOT MODIFY THIS METHOD.
     */
    public BookMain() {
        letterData = new LetterTally();
        wordData = new WordTally();
        sentenceData = new SentenceTally();     
    }

    /**
     * DO NOT MODIFY THIS METHOD.
     *
     * You are still allowed to change the input file name to see the output for
     * different files.
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        BookMain bm = new BookMain();
      
        Scanner input = new Scanner(new File("PrideAndPrejudice.txt"),"UTF-8");
        bm.readHeader(input);
        bm.analyzeBookText(input);
        System.out.println(bm.statToString());
        input.close();
    }

    /**
     * This method analyzes the book text data. Complete this method.
     *
     * @param input
     */
    public void analyzeBookText(Scanner input) {
        //
        // WRITE YOUR CODE HERE TO PROCESS THE BOOK DATA
        //
      

    }

  
    /**
     * DO NOT MODIFY THIS METHOD. YOU MAY USE IT TO SEE THE ANALYSIS RESULTS.
     *
     * @param letterData
     * @param wordData
     * @param sentenceData
     */
    public String statToString() {
        String s = "";

        s += "Raw letter count: " + letterData.totalCount() + " ";
        s += "Letter entropy: " + letterData.computeEntropy() + " ";
        s += "Raw word count: " + wordData.getRawCount() + " ";
        s += "Unique word count: " + wordData.getUniqueCount() + " ";
        s += "Longest word: " + wordData.longestWord() + " ";
        s += "Average word length: " + wordData.avgWordLength() + " ";
        s += "Sentence count: " + sentenceData.getCount() + " ";
        s += "Average sentence length: " + sentenceData.avgSentenceLength() + " ";

        return s;
    }

    /**
     * DO NOT MODIFY THIS METHOD. IT EATS UP THE HEADER LINES
     *
     * @param input
     */
    private void readHeader(Scanner input) {
        int nHeaderLine = 31; // a fixed number of header lines for the book.
        int nCurLine = 0;
        while (input.hasNext() && nCurLine < nHeaderLine) {
            input.nextLine();
            nCurLine++;
            if (nCurLine == nHeaderLine)
                break;
        }
    }
}

--------------------------------------------------------------------------------

public class LetterTally {

    /** Declare instance variables. */
    int rawCount;

    /**
     * Default constructor. Initialize the instance variables in this method.
     *
     */
    public LetterTally() {
        rawCount = 0;
    }
}

-----------------------------------------------------------------------------

public class SentenceTally {

    /** Declare instance variables. */
   public String sentence;
    /**
     * Default constructor. Initialize the instance variables in this method.
     *
     */
    public SentenceTally() {
       
    }
   
    }

---------------------------------------------------------------------------------

public class WordTally {

    /** Declare instance variables. */
   private ArrayList<String> word;
    /**
     * Default constructor. Initialize the instance variables in this method.
     *
     */
    public WordTally(ArrayList<String> word) {
       ArrayList<String> word = new ArrayList<>();
    }

------------------------------------------------------------------------------------------

Explanation / Answer

hi, i have tried to write most of the code, since i donot have your input file with me, i tried to write whatever suitable code i can write... Please check, if you need to tweak the code a bit here and there... thanks!

Please do a thumbs up, if the answer helped you in any manner.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote