This homework asks you to design and implement a class called wordCollection that maintains a collection of String objects and supports the operations insert, search, and delete on this collection. I would like the collection of String objects to be maintained in a 2-dimensional array as follows. Let M be the number of rows in the 2-dimensional array. For a given string s, compute an index by adding up the ASCII values of the characters in s and then taking the remainder with respect to M. This will give, for each string s, an index in the range [0, M-1]; let us denote this index h(s). The main idea is to store string s in row h(s). To search for a given string s, we compute h(s) and then perform a linear scan of the row to find s. The delete is similar to search, except that at the end s has to be deleted from the row h(s).
What to submit: Well-documented Java code fragment showing names and types of data members. The comments should clearly describe the purpose of each data member.
public wordCollection() public wordCollection(int M)The user calls the default constructor when she does not know (or does not care) how many strings she expects to store. In this case, the programmer has to decide how many rows to allocate. The user calls the second constructor above, with argument M when she knows that she would like to be allocated M rows.
Despite what I have specified here, there are still several choices you need to make. For example, how large should you initially make each of the rows, etc. Your code will be judged on the quality of and justification for these choices.
What to submit: Submit Version 1 of the wordCollection class, with just the data members and constructors. Call this file wordCollection1.java. Your code should compile and you should make sure that your code is well-documented.
public void insert(String s)
This method should take care of the possibility that row h(s) may be full, by expanding rows when needed. Note that the number of rows does not change over the lifetime of the wordCollection object.
What to submit: Submit Version 2 of the wordCollection class, with just the data members, constructors, and the insert method. Call this file wordCollection2.java. Your code should compile and you should make sure that your code is well-documented.
Row 0 word1 word2 word3 ... word10 word11 word12 Row 1 EMPTY Row 2 word1 word2 word3 ... word10 word11 word12 word13 ... word20 word21 word22 word23 ... word30 Row 3 word1 word2 .... ....In your program wordCollectionTester1, you should call the printAll method after you have inserted all the words.
What to submit: Submit Version 3 of the wordCollection class. This should contain everything that Version 2 contained and additionally the printAll() method. Call this file wordCollection3.java. Your code should compile and you should make sure that your code is well-documented. Also submit wordCollectionTester1.java and the output obtained from executing wordCollectionTester1.java.
[0, 49]: n1 [50, 99]: n2 [100, 149]: n3 .... ....Here n1 is the number of rows whose length is between 0 and 49 (inclusive), n2 is the number of rows whose length is between 50 and 99 (inclusive), etc.
Modify your program wordCollectionTester1, so that after the words in words.dat are inserted into the wordCollection object, it calls the printFrequency method. Call this new program wordCollectionTester2.
What to submit: Submit Version 4 of the wordCollection class. This should contain everything that Version 3 contained and additionally the printFrequency() method. Call this file wordCollection4.java. Your code should compile and you should make sure that your code is well-documented. Also submit wordCollectionTester2.java and the output obtained from executing wordCollectionTester2.java.