Start by snarfing 20_maps_cps006_spring10.
A Map might be used to associate student IDs with complete student records, or
words to their definitions (like a real dictionary). What other examples of
maps can you think of?
In Java, the
TreeMap class,
is used to model the concept of a map given above. In the remainder of this
activity, you will use one or more
TreeMap objects to discover several interesting statistics about words in a file: how
many times a word appears in a given file, or on which lines a word appears in
a file.
There is one class defined for this activity: WordLines. You should start by reading over the code in this class and making sure you understand it.
Explain the following details about the code in a README file:
Integer object and how is it used
in this class?printResults work for any kind of map
Complete the method, getLineNumbers, that creates a new Map with
words as the key and the set of line numbers on which that word appears as
the value. This method should get the data for each word from the Scanner passed
it.
Complete the method, getFrequencies, that creates
a new Map with
letters as the key and the set of words which start with that letter as
the value. This method should get the data for each word from the Scanner passed
it.
Create a README file with both of your names in it if you work with a partner.
Electronically submit the classwork through Eclipse your Java code and README file to the ClassworkApr20Maps folder.