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

There is some debate on influence of Jane Austen on Charlotte Bronte work as a w

ID: 3859978 • Letter: T

Question

There is some debate on influence of Jane Austen on Charlotte Bronte work as a writer (and in general on all three Bronte sisters'). If you are interested in finding more, feel free to google for their works and the debate. For this exercise, using the publicly available books on Project Gutenberg (http: //www.gutenberg.org), you are asked to find the top 10 words and number of times they occur in books by Charlotte Bronte but not used by Jane Austen. To simply this exercise, we will only use the following books: HashMap (or HashTree) Java Collection will come handy for finding and keeping the count of words. You are only allowed to use Java Collections as described in Chapter 11 of our class textbook. To receive full credit, submit the following: -Java source code file(s) -Nicely formatted report containing a table of top 10 words found in Charlotte Bronte's books and not in Jane Austen's and their counts, and a summary of your insights from this exercise including how this type of analysis can be useful and any suggestions for improvements. -Don't submit the text files for the books!

Explanation / Answer

The required code is as follows.Hope it is clear as I have used HashMap technique as you needed. I tried to make it as simple as I can and here we are with the program.

WCount.java

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
/**
* Java program to find count of repeated wrd in a file.
*
* @author Akshay Bisht
*/
public class WCount {

public static void main(String args[]) {
Map<String, Integer> wmap = WordMapping("C:/gutten.txt");
List<Entry<String, Integer>> lst = sortDecrease(wmap);
System.out.println("List of repeated word from file and their count");
for (Map.Entry<String, Integer> entry : lst) {
if (entry.getValue() > 1) {
System.out.println(entry.getKey() + " => " + entry.getValue());
}
}
}

public static Map<String, Integer> WordMapping(String fn) {
Map<String, Integer> wmap = new HashMap<>();
try (FileInputStream flIpStream = new FileInputStream(fn);
DataInputStream data = new DataInputStream(flIpStream);
BufferedReader buff = new BufferedReader(new InputStreamReader(data))) {
Pattern patt = Pattern.compile("\s+");
String str = null;
while ((str = buff.readLine()) != null) {
str = str.toLowerCase();
String[] wrd = patt.split(str);
for (String word : wrd) {
if (wmap.containsKey(word)) {
wmap.put(word, (wmap.get(word) + 1));
} else {
wmap.put(word, 1);
}
}
}
} catch (IOException ioex) {
ioex.printStackTrace();
}
return wmap;
}

public static List<Entry<String, Integer>> sortDecrease(Map<String, Integer> wmap) {
Set<Entry<String, Integer>> entry = wmap.entrySet();
List<Entry<String, Integer>> lst = new ArrayList<>(entry);
Collections.sort(lst, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> obj, Map.Entry<String, Integer> obj1) {
return (obj1.getValue()).compareTo(obj.getValue());
}
});
return lst;
}
}

Please rate the answer if it helped.....Thankyou

Hope it helps.....

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