Write in Java in Eclipse Must use ArrayList Interface and Ge
Write in Java in Eclipse. Must use ArrayList, Interface and Generics. Cannot use HashMaps and TreeMap.
Your program must ask the user for an input text file (please handle potential I/O errors properly), and count how many words the file contains and display the following statistics:
-Display each word in the text along with its rank and frequency. You can assume that a word is defined as anything that the method Scanner.next() returns and only contains letters. For example “U2”, “data-base” and “hi!” should not be counted as words. Your program does not have to be case-sensitive. For example, the words “hi” and “Hi” can be considered as same words. The list of rank/word/frequency must be displayed in descending order of frequency, and all words with the same frequency must be displayed in alphabetical order (uppercases before lowercases).
-The list of rank/word/frequency must be displayed in descending order of frequency, and all words with the same frequency must be displayed in alphabetical order (uppercases before lowercases).
Solution
import java.util.Arrays; import java.util.HashMap; import java.util.Map; interface IFrequencyCounter{ public String[] getMostFrequenctWords(String content, int numberOfwords ); } public class FrequencyCounter implements IFrequencyCounter{ /** * This is the Frequency Class * which has only one property count. * This is used to save autoboxing/unboxing * overhead when using maps. */ private class Frequency{ private Frequency(){ this.count = 1; } private int count; public int getFrequency(){ return this.count; } public void incrementFrequency(){ this.count++; } public void setCount(int count){ this.count = count; } } /** * Token class extends Frequency. This is * used to maintain word frequency relationship. * (Just like a pair.) */ private class Token extends Frequency{ private Token(String word, int count){ super(); this.word = word; setCount(count); } private String word; } /** * This method returns String array sorted by most frequent word. If null/empty string * is provided as input then empty array is returned. If numberOfWords is greater then * unique words then all the words are returned. * * @see com.evernote.util.IFrequencyCounter#getMostFrequenctWords(java.lang.String, int) */ @Override public String[] getMostFrequenctWords(String content, int numberOfwords) { // basic validations if( null == content) content = \"\"; if(numberOfwords <= 0) return new String[0]; int maxSofar = 0; HashMap