Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i would like some help in completing this exercise. Thank You import java.util.Scanner; import java.io.File; public class BookMain { LetterTally letterData; WordTally wordData; SentenceTally sentenceData;

i would like some help in completing this exercise. Thank You

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

public class BookMain { LetterTally letterData; WordTally wordData; SentenceTally sentenceData; public BookMain() { letterData = new LetterTally(); wordData = new WordTally(); sentenceData = new SentenceTally(); }

public static void main(String[] args) throws Exception { BookMain bm = new BookMain(); Scanner input = new Scanner(new File("PrideAndPrejudice.txt")); 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 // }

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; }

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; } } }

I would like some help in completing this exercise. Thank You

public class LetterTally {

/** Declare instance variables. */

/** * Default constructor. Initialize the instance variables in this method. * */ public LetterTally() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns the number of total letters in the book. * * @return the total number of letters in the book */ public int totalCount() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns the number of times a letter appear in the book * * @param ch * - the letter of interest * * @return */ public int freqChar(char ch) { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method computes the entropy of the letters. To compute the entropy, for * each letter, compute the ratio (say it p) of the frequency count of the * letter to the total frequency count of all letters. Then, compute the * following value: p * Math.log (1 / p). Return the sum of the values, rounded * to the nearest integer value. * * @return */ public int computeEntropy() { throw new UnsupportedOperationException("replace with your implementation"); } }

public class SentenceTally {

/** Declare instance variables. */

/** * Default constructor. Initialize the instance variables in this method. * */ public SentenceTally() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns the average number of words in a sentence. The value has * to be formatted to a String with the following statement: * * Assuming that average is the variable that contains the average number of * words in a sentence, * * String s = String.format("%.2f", average); * * @return the average number of words in the sentences in the book in a String * format */ public String avgSentenceLength() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns the number of sentences in the book. * * @param token * * @return the number of sentences in the book */ public int getCount() { throw new UnsupportedOperationException("replace with your implementation"); }

}

public class WordLib {

/** * This method takes a token (a space-separated letter sequence in the book * data) and return a new string that does not contain any of the symbols listed * below. That is, it removes the symbols from the word. * * Symbols to be removed: , . ? ; ! : ' " ( ) _ \u201C \u201D * * The \u201C and \u201D are the left and right double quotation marks in * Unicode. * * @param w * a token read from the book * @return a string without the listed symbols */ public static String cleanWord(String w) { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method takes a token (a space-separated letter sequence in the book * data) and return a new array of words when the token contains two words * separated by double dashes. Assume that no token contains two double dashes * (e.g., hello--world--houston) or has triple dashes. * * If "hello--world" is the input, a new array of length 2 must be returned * where the first and the second element of the array are "hello" and "world", * respectively. There are edge cases. For example, "Hello--" or "--World". For * such cases, the first and/or the second element of the new array will have an * empty string. * * If the input does not contain a double dash, the first array element will has * the input token as-is and the second element will be set to an empty string. * * @param w * a token read from the book * @return an array of words */ public static String[] splitDash(String w) { throw new UnsupportedOperationException("replace with your implementation"); }

}

public class WordTally {

/** Declare instance variables. */

/** * Default constructor. Initialize the instance variables in this method. * */ public WordTally() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns the raw count of the words in the book. A word can be * counted multiple times if it appears multiple times. * * @return the raw count of the words in the book */ public int getRawCount() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns the unique count of the words in the book. A word must be * counted only once when it appears multiple times. * * @return the unique count of the words in the book */ public int getUniqueCount() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns the average length of the words used in the book. The * average length has to be formatted in a String with the following statement: * * Assuming that averageLength is the variable that contains the average word * length, * * String s = String.format("%.2f", averageLength); * * @return the average length of the words in the book in a String format */ public String avgWordLength() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns the length of the longest word used in the book * * @return the length of the longest word in the book */ public int longestWord() { throw new UnsupportedOperationException("replace with your implementation"); }

/** * This method returns how many times a word appear in the book * * @param ow * a Word object * @return the number of occurrences of the input word */ public int freqWord(Word ow) { throw new UnsupportedOperationException("replace with your implementation"); } }

public class Word {

/** Declare instance variables. */

/** * Default constructor. Initialize the instance variables in this method. * */ public Word(String w) { throw new UnsupportedOperationException("replace with your implementation"); }

/** You may add more methods needed to complete the program */

}

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_step_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions

Question

give an example of a dataset where n = 8 and the s = 0

Answered: 1 week ago