Output and Screenshot
Project 2:Word Frequency List Due Date: Monday Nov. 18, 11:00 PM
Overview In this assignment, we use linked list to count the words from a given text le or URL and print the words by their frequnct order. The iterable class "Frequency" uses a "Node" to represent each word and its frequency. The Node class is given here:
class Node {
private E key;
private int count;
private Node next;
Node(E item){
key = item;
count = 1;
next = null;
}
}
Frequency class can insert words into a linked list. When a new word is inserted, it adds the word into the list. If the word exists in the list, we simply increment the value of "count" for the word. We also keep the words in the linked list by their frequency order. Therefore, when the frequency of a word has changed, we have to move the word to correct position in the linked list. If two words have same frequency, they are sorted alphabetically. For example: if we insert three words Alice, Bob, Cathy, we will have
Code examples To read a webpage at the given URL, and print the content (the html le) of the webpage:
In in = new In(urlName);
while (!in.isEmpty()) {
String s = in.readLine();
System.out.println(s);
freq.insertWords(s);
}
To read the text le and print the content.
In in = new In(fileName);
while(!in.isEmpty()) {
String s = in.readLine();
System.out.println(s);
freq.insertWords(s);
}
The InsertWords method of the Frequency class takes a sentence, split the sentence into words, and calls "insert" method of the Frequency class to insert each single word into the Linked List. The InsetWords method is shown here:
public void insertWords(String str){
String delims = "[.,?!’\"()}{;/<>&=#-:\\_]+";
String[] words = str.split(delims);
for (String s: words){
insert((E)s);
Word Frequency file:///Users/anwar/Google Drive/Other_Courses/Old/VIU/Fall2016/project...
1 of 2 11/4/16, 11:38 PM
}
Objectives This project will allow you practice linked list insert, remove, and test development.
Grading (30%) Public Tests (60%) Secret Tests (10%) Style
Code Distribution The code distribution provides you with the following:
frequency package → This package includes a linked list class and a driver. Executing the main method of in WordFrequency class prints the output. utils package →Reads the input source. tests package → Includes the public test model. Text files → Represent the expected output for public tests.
Specifications You are expected to implement the insert method for Frequency class. The other classes have been provided and you should not modify them. You can add other helper methods. For example, a find method checks if a word exists in the list. a remove method removes a word from the list, an insertnode method inserts a node in the correct location etc.
Notice you are not required to write student tests for credit, however, if you need assistance during office hours you need to bring student tests that illustrates the problem you are experiencing. Also, keep in mind the percentage associated with secret tests is high, so you need to test your project thoroughly.
Requirements The main method iterates through linked list of Frequency class and prints MAX number of words from the list. "inputSourceName" is the text file name or the URL for the webpage. You can create your test files too. You can also test with URLs. Pay attention to the corner cases, where words are inserted at the start of the linked list, at the end of the linked list. Create small text files, test your code with small files. Test with bigger files such as War and Peace when you feel confident with your program. See Style Guidelines for information regarding style. We cannot provide any information regarding release nor secret tests. Once your project has been graded, you can see a TA if you would like to find out why you failed a release or secret test.
Suggestions on How To Start the Project Study the public tests before starting implementing your project.
Submission Compress the project into a single zip file, and submit the zip file to Moodle. File name must be in this format: lastname_firstname_p2.zip. For example: mamat_anwar_p2.zip.
Academic Integrity Please make sure you read the academic integrity section of the syllabus so you understand what is permissible in our programming projects. We want to remind you that we check your project against other students' projects and any case of academic dishonesty will be referred to the Office of Student Conduct.
Word Frequency file:///Users/anwar/Google Drive/Other_Courses/Old/VIU/Fall2016/project...
2 of 2 11/4/16, 11:38 PM