There are three problems in this homework. For each problem, if your program resides in a single file, submit that file into the dropbox in ICON named Homework3; if your program resides in multiple files, submit a zip of those files or of the directory containing those files.

Problem 1

During the lectures on September 7 and 9, we discussed an implementation of the class MyDocument, a class for storing the words in a document along with their frequencies. The code for this class, together with the MyWord class that it uses, and a class containing a main method for testing, can be found here . Add a public instance method to the class MyDocument with the following signature: String [] wordSet(). If d1 is a variable referring to a MyDocument object, d1.wordSet() should return an array containing the words in d1. The length of the array should exactly equal the number of distinct words in d1.

Problem 2

Add a public instance method to the class MyDocument with the following signature: double similarityTo(MyDocument d2). If d1 and d2 are variables referring to two MyDocument objects, then d1.similarityTo(d2) should return the similarity between d1 and d2, which is defined as the number of words that are common to d1 and d2, divided by the square root of the product of the number of distinct words in d1 and the number of distinct words in d2.

Note that if d1 and d2 don't have any word in common, their similarity is 0. On the other hand, the similarity between d1 and d1 is 1. In general, the similarity is between 0 and 1.

Problem 3

Implement a class MyDocumentLL that provides the same functionality as the MyDocument class, but uses a doubly linked list to store the MyWord objects instead of an array of MyWord objects as done in MyDocument. Thus, each node of the doubly linked list should have a field for a MyWord object, as well as fields for the previous and next node in the doubly linked list. You need to write the class corresponding to a node of the doubly linked list as well.

The class MyDocumentLL should provide the same functionality as the MyDocument class here . This means that the class should have the following public methods, and they should output exactly what the corresponding methods in MyDocument output:

The class MyDocumentLL should also have a constructor that takes as input the name of a file. There is no need to add methods corresponding to those in Problems 1 and 2.

Problem 3 is the most substantial part of this homework and is worth 50 percent of the grade on the homework. The lectures and discussion section this week (Sep 12--16) will be quite useful for this; reading Sections 3.2 and 3.3 of the book will help as well.