Question: Question 1: Counting Characters with a Linked List using java You will count the number of characters in Charles Dickens Great Expectations. The counts (number

Question 1: Counting Characters with a Linked List using java You will count the number of characters in Charles Dickens Great Expectations. The counts (number of occurrences) for each unique character will be stored along with the characters in the nodes of a linked list, as described below. As you read through the text file, you will, character-by-character, keep track of the number of times you see each character. The Node Class (referred to as Link class in your textbook) Create a Node class as follows: Each Node will contain a character (char) variable that will hold a character found in the text file. Include a getLetter() method that will return the char. Each Node will also contain an integer (int) variable that will hold a count of the number of times the character is seen in the text. Include a getCount() method that will return the integer. Include a setCount(int newCount) method that will accept an integer and set the count to the given value. Return a boolean (true if the count is updated, false otherwise). Before updating the count, verify that newCount is a valid (zero or positive) integer. Each Node will have a reference to the next Node in the linked list. That is, each Node will hava a data member that is itself of type Node. Include a getNext() method that will return the reference to the next Node in the list. Include a setNext(Node newNext) method that will set the reference to the next Node in the list to the given parameter. Add a toString() method that will print the character and its count, in the format a 12 (the character bounded by single quotes, followed by a space, and then the count). The data members should be private and the accessor & mutator methods should be public. Note that even though the 2140 programming standards state that the data should be contained in a separate class from Node, for this assignment please keep the data inside the Node class to simplify things. In the future, we will use a separate class for the data fields. The Linked List Class Create a sorted linked list class using the above Node class. The LinkedList class will have a reference to the first Node in the list. That is, the LinkedList class will have a (private) data member called first, which is of type Node. The Linked List will be ordered by character. Use basic <, >, ==, etc. comparisons when comparing charac- ters. Include standard linked list methods (i.e. isEmpty() that returns a boolean, and remove() that returns the first Node in the list). Write an insert method that will accept a character and a count. This method should verify that there is not already a Node for the given character, and then insert a new Node so that the list is kept in order. If a Node for the given character already exists, do not add a new Node. Instead, modify the existing Node by adding the given count to the existing count. Create an incrementCount method that will accept a character as a parameter. Search the list for the given character. If a Node containing that character is found, increment the count. If a Node containing that character is not found, create a new Node with a count of 1 and insert it into the linked list. Write a toString method that will print the linked list (both characters and their counts), by calling the toString method for each of the Nodes in the list. The output should appear in the format: a 12 s 24 d 9 f 32 Your Main Class (please name it A2Q1) The provided file 1400-0.txt (containing the text of Great Expectations) was obtained from http://www. gutenberg.org/ebooks/1400. Create a new linked list and then process the file 1400-0.txt character by character, incrementing the ap- propriate counts in your linked list as you go. After processing the entire file your linked list will contain all characters and their associated counts. Print out your linked list (using the toString method you wrote above). Sum all of the counts in your linked list and print a grand total of the number of characters in the file. Additional Notes Count all characters in the file, including special characters, newlines, line feeds, etc. Treat any character read from the file as you would any letter, and add it to your list using the same character comparisons. HINT: Create a small text file, for which you can manually count the number of characters, and use it for testing while coding your solution. Even though this is not the most efficient way to solve this problem, please follow the instructions above to demonstrate your understanding of linked lists. Please place all classes for question 1 in the same file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!