Explanation of Solution
Modified definition of “ListNode” class in Listing 12.4:
The modified definition of “ListNode” class in Listing 12.4 is given below:
//Define class "ListNode2"
public class ListNode2<E>
{
//Declare variable "data" and "link" in type parameter
private E data;
private ListNode2<E> link;
//Create default constructor for "ListNode2"
public ListNode2()
{
link = null;
data = null;
}
/* Create parameterized constructor for "ListNode2" */
public ListNode2(E newData, ListNode2<E> linkValue)
{
/* Assign value to "data" and "link" */
data = newData;
link = linkValue;
}
//Accessor method for assign value to data
public void setData(E newData)
{
data = newData;
}
//Mutator method for return data
public E getData( )
{
;&#x...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Scrabble Help: The file dictionary.txt contains all of the words in the Official Scrabble Player's Dictionary, Second Edition. Note: this list contains some offensive language. Write a class, WordLists, in Java that generates useful word lists for scrabble players using this list. Your class should contain the following methods: WordLists(String fileName): a constructor that takes the name of the dictionary file as the only parameter. lengthN(int n): returns an ArrayList of all length n words (Strings) in the dictionary file. endsWith(char lastLetter, int n): returns an ArrayList of words of length n ending with the letter lastLetter containsLetter(char included, int index, int n): returns an ArrayList of words of length n containing the letter included at position index. So for example the word "cannon" would be on the list returned by containsLetter('o',6,4) because it contains the letter 'o', at index 4, and is length 6. multiLetter(int m, char included): returns an ArrayList of…arrow_forwardWould you please help me to create the my elif under the class OrderedList? I am not really so sure on what to code if the node has already a value. Thank you. class Node: def __init__(self, data): self.data = data self.next = None class OrderedList: list = [] head = Node(None) tail = Node(None) prev = Node(None) cur = Node(None) def insert(self, val): self.newNode = Node(val) if self.head.data == None: self.head = self.newNode self.tail = self.newNode self.list.append(self.newNode.data) elif self.head.data != None: self.head = self.newNode self.tail = self.newNode self.list.append(self.newNode.data) #main myList = OrderedList() myList.insert(10)arrow_forwardYou are familiar with ArrayList and have used it in different capacities. The most prominent feature of ArrayList is that it expands automatically as elements are added to it. It can be traversed using a for loop, for each loop and iterator( which you have implemented in Lab 2).In this lab you are going to implement your own ArrayList and its functionalities.Task 1.1: Create a class Generic ArrayList with attributes.Task 1.2: Implement a constructor for your ArrayList class.Task 1.3: Implement add() method for adding elements to ArrayList. Remember, ArrayList adds elements dynamically. It doesn't depend on user defined size.Task 1.4: Implement remove() method for removing an element from a specific index. Remember, ArrayList stores elements in a consecutive sequence. If an element is removed from middle you have to re-adjust the elements in the correct sequence. Note: Break down your implementation by defining helper methods for different tasks, rather than implementing your logic in a…arrow_forward
- To demonstrate working with ArrayLists, we will be working with four source files: a Dessert class, two classes that extend Dessert called IceCream and Cake, and a TestDessert class. The TestDessert class contains a main() method that declares an ArrayList to hold Dessert objects. This ArrayList is referenced by the variable named "list". Examine TestDessert's main() method and notice the four comments. You are to implement code that accomplishes the tasks described in each step. For step 1, you are to populate the ArrayList with 10 IceCream and Cake objects. These objects should be inserted into the ArrayList at random. This means each run of the program should produce an ArrayList with different proportions of IceCream and Cake objects. After this operation, the ArrayList should contain 10 total objects (IceCream and Cake objects). Display the ArrayList after the operation. For step 2, if the first and last dessert in the ArrayList are different (one is IceCream and the other is…arrow_forwardWrite a method called addSmallest to be considered in a class outside the KWArrayList class. This method will have a parameter list of class type KWArrayList. The method will add the smallest element of the list, at the end of the list. Method heading: public static void addSmallest (KWArrayList list) Before run: 3 5 100 40 67 22 After run: 3 5 100 40 67 22 3arrow_forwardYou are going to implement a program that creates an unsorted list by using a linked list implemented by yourself. NOT allowed to use LinkedList class or any other classes that offers list functions. It is REQUIRED to use an ItemType class and a NodeType struct to solve this homework. The “data.txt” file has three lines of data 100, 110, 120, 130, 140, 150, 160 100, 130, 160 1@0, 2@3, 3@END You need to 1. create an empty unsorted list 2. add the numbers from the first line to list using putItem() function. Then print all the current keys to command line in one line using printAll(). 3. delete the numbers given by the second line in the list by using deleteItem() function. Then print all the current keys to command line in one line using printAll().. 4. putItem () the numbers in the third line of the data file to the corresponding location in the list. For example, 1@0 means adding number 1 at position 0 of the list. Then print all the current keys to command line in one…arrow_forward
- Write a method called addBiggest to be considered in a class outside the KWArrayList class. This method will have a parameter list of class type KWArrayList. The method will add the biggest element of the list, at the end of the 1ist. Method heading: public static void addBiggest (KWArrayList list). Before run: 35 100 40 67 22 After run: 3 5 100 40 67 22 100arrow_forwardJavaarrow_forwardA Maze Room : In this lab, we will make a maze game. The maze is based on Linked Lists. Instead of having one possible direction (next), we will have 4 possible directions. Rooms: Use the below code as a basis to build your own room class. Implement this class in the file room.py A room will be the basic object for our maze game. A room can have 4 doors (pertaining to north, south, east, and west). Attached to each these directions we have either another room or None (we could also imagine that the None doors are just walls). We want the player to be able to tell what room they are in. Each room will have a unique description. When the player enters a room, the program will describe the room. This way the player will know if they went back to a room that have already been to. You MAY NOT change the method's arguments/names in ANY way. class Room():def __init__(self, descr):#Description of the room to print out#These should be unique so the player knows where they areself.descr =…arrow_forward
- Question 7 Which of the following class implements the List interface? Collection AbstractList Listlterator ArrayList«E>arrow_forwardPlease may you do the attached in Java code , adding a method to an existing code .arrow_forwardWhat is the difference between the ArrayList class and the LinkedList class?arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT