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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
