CompSci 6- Classwork 17 - March 30, 2010
10 pts

This classwork involves solving a single APT problem: Thesaurus. You should snarf the 17_thesaurus_cps006_spring10 project. For the problems below, you will either complete code in Thesaurus.java or enter your answer in your README file.

Thesaurus

  1. Review the Thesaurus APT.

    Assume you have the following entries

    {"C B A A B C", "F D E", "I G H I", "B G C E F"}
    
    what should edit return? Enter your answer in your README.

  2. Complete the method sToSet that converts a String of the form in the assignment ("B G C E F") to a Set. In your code, you should create and return a TreeSet, rather than a Set. Why does that work?

  3. Complete the complementary method collToS that converts a Collection to a String of the form above. How would you call collToS on a TreeSet?

  4. Adapting your work from then the set classwork from last class period, complete:
    1. numInCommon so that it returns the number of elements in common between two sets, a and b
    2. union so that it returns the union of two sets, , a and b.
    Note: Your methods should not change a or b.

  5. Add code to the main method to test out your sToSet, collToS, numInCommon, and union methods.
  6. Using the methods above, you should write edit and complete the APT. You can use the the pseudocode below as a guide.

    Convert entry to an ArrayList of sorted Sets: entrySet
    Keep merging entries until nothing is merged
      Let n be the number of elements in entrySet
      For every pair (i,j) where 0 ≤ i,j < n and i < j
        if entrySet[i] and entrySet[j] have ≥ 2 in common
          merge entrySet[i] and entrySet[j]
    Convert list of Sets to an array of Strings
    Sort the entries in alphabetical order
    

Submitting

Submit as ClassworkMarch30Thesaurus.