9. A concordance is an alphabetical word list for a passage of text. Each word i
ID: 3831231 • Letter: 9
Question
9. A concordance is an alphabetical word list for a passage of text. Each word in the concordance is mapped to an Integer indicating the frequency of the word's occurrence. The constructor of Concordance has one string parameter that identifies the text file to be read. An incompleteConcordance class is below. public class Concordance public Concordance (String nameofFile)f concord new TreeMapkString, Integer create Concordance (nameofFile); Constructor //nameof File the text file being read public void createConcordance (string filename) //create a TreeMap of words mapped to their Integer frequencies public void printConcordance //Prints the alphabetized list of words paired with their frequencies private MapExplanation / Answer
a) public void createConcordance(String filename)
{
Scanner inFile = new Scanner(filename);
while(inFile.hasNext())
{
String s= inFile.next();
if (concord.containsKey(s))
{
concord.put(s,concord.get(s)+1);
}
else
concord.put(s,1);
}
b)
public void printConcordance()
{
for(Map.Entry<String,Integer> entry : concord.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
System.out.println(key + " occurs " + value + " time(s).");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.