Question
Please help me with all of the TODO, thank you. import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * Counts words in a given list of
Please help me with all of the "TODO", thank you.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* Counts words in a given list of lines from a file.
*/
public class WordCounter {
/**
* List of lines of words to count.
*/
private ArrayList
/**
* Map storing the count of each word in the list of lines.
* Each word will be a key, and the associated counts of each word will be the values.
*/
private Map
/**
* Creates WordCounter based on the given list of lines.
* Starts the process of generating the count of each word in the list.
* @param lines of words to count
*/
public WordCounter(ArrayList
this.lines = lines;
this.wordCount = new HashMap
this.generateWordCounts();
}
/**
* Calculates the count of each word in the list of lines.
* Traverses the list of lines, and keeps track of the count of each word.
* Stores each word as a key and its associated count as a value in the HashMap
*
* Note, the words (keys) are case-sensitive.
* e.g. "Hello" is considered a different word (key) than "hello".
* e.g. "UFO" is considered the same word as "UFO".
*
* Hint(s):
* - Traverse the list of lines and split each one into an array of words (strings). Use the words as keys and
* the associated counts as values in the HashMap
*
* Example(s):
* - If the list of lines contains:
* "war and the"
* "war the peace peace"
* "the war the"
*
* Calling generateWordCounts() would populate the HashMap
* ("war", 3), ("and", 1), ("the", 4), ("peace", 2)
*
* Example(s):
* - If the list of lines contains:
* "War and the"
* "war the Peace peace"
* "thE war The"
*
* Calling generateWordCounts() would populate the HashMap
* ("War", 1), ("war", 2), ("and", 1), ("the", 2), ("The", 1), ("thE", 1), ("Peace", 1), ("peace", 1)
*/
private void generateWordCounts() {
//TODO Implement method
}
/**
* Gets the HashMap
* @return wordCount
*/
public Map
return this.wordCount;
}
/**
* Gets a list of words that appear a particular number of times, indicated by the given threshold.
*
* Hint(s):
* - For each word (key) in the wordCount map, check if the associated word count (value) is >= threshold.
*
* Example(s):
* - If the list of lines contains:
* "war and the"
* "war the peace peace"
* "the war the"
*
* Calling getWordsOccuringMoreThan(3) would return an ArrayList
* Because "war" appears 3 times and "the" appears 4 times.
*
* Example(s):
* - If the list of lines contains:
* "War and the"
* "war the Peace peace"
* "thE war The"
*
* Calling getWordsOccuringMoreThan(2) would return an ArrayList
* Because "war" appears 2 times and "the" appears 2 times.
*
* Example(s):
* - If the list of lines contains:
* "War and the"
* "war the Peace peace"
* "thE war The"
*
* Calling getWordsOccuringMoreThan(-1) would return an ArrayList
* "War", "war", "and", "the", "The", "thE", "Peace", "peace"
* Because all words appear more than -1 times.
*
* @param threshold (minimum word count) for words to include in the returned list,
* where each word has a word count >= threshold.
* @return list of words, where each has a count >= threshold
*/
public ArrayList
ArrayList
//TODO Implement method
return result;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started