Question: Need this output in JAVA: Sample Test Output Nodes of doubly linked list: Miqun Robinson 908-239-4740 Michael Davis 443-904-2152 Michael Donellson 443-924-2153 Allison Whitehead 650-455-5076

Need this output in JAVA:

Sample Test Output

Nodes of doubly linked list: Miqun Robinson 908-239-4740 Michael Davis 443-904-2152 Michael Donellson 443-924-2153 Allison Whitehead 650-455-5076 David Lamm 484-885-0859 Madison Jackson 215-222-3359 Zachary Whitehead 484-223-1234

Starting search from head test... Enter search item (or q to quit):215 Madison Jackson 215-222-3359 Michael Davis 443-904-2152 Michael Donellson 443-924-2153

Enter search item (or q to quit):443 Michael Davis 443-904-2152 Michael Donellson 443-924-2153

Enter search item (or q to quit):all Allison Whitehead 650-455-5076

Enter search item (or q to quit):

This is my code. Having trouble getting this to run:

package edu.dccc.datastructures; import java.io.*; import java.util.*; class PhonebookData implements Comparable { String name; String mobilePhone; public PhonebookData(String name, String mobilePhone) { this.name = name; this.mobilePhone = mobilePhone; } public String getName() { return name; } public String getMobilePhone() { return mobilePhone; } public String toString() { return name + " " + mobilePhone; } public static int compare(String str1, String str2) { int l1 = str1.length(); int l2 = str2.length(); int lmin = Math.min(l1, l2); for (int i = 0; i < lmin; i++) { int str1_ch = str1.charAt(i); int str2_ch = str2.charAt(i); if (str1_ch != str2_ch) { return str1_ch - str2_ch; } } // Edge case for strings like // String 1="Geeks" and String 2="Geeksforgeeks" if (l1 != l2) { return l1 - l2; } // If none of the above conditions is true, // it implies both the strings are equal else { return 0; } } @Override public int compareTo(Object o) { PhonebookData pd = (PhonebookData)o; return compare(this.name,pd.name); } } class DoublyLinkedList { static SortedSet sortedSet = new TreeSet(); class Node { PhonebookData data; Node previous; Node next; public Node(PhonebookData data) { this.data = data; } } public SortedSet searchTailFirst(String searchItem) { Node current = tail; if (tail == null) { System.out.println("List is empty"); return null; } // System.out.println("Nodes of doubly linked list: "); while (current != null) { //Checks each node by incrementing the pointer. if (current.data.name.toLowerCase().contains(searchItem.toLowerCase().strip()) || current.data.mobilePhone.contains(searchItem)) { sortedSet.add(current.data); } current = current.previous; } return sortedSet; } //Represent the head and tail of the doubly linked list Node head, tail = null; public void addNode(PhonebookData data) { //Create a new node Node newNode = new Node(data); //If list is empty if (head == null) { //Both head and tail will point to newNode head = tail = newNode; //head's previous will point to null head.previous = null; //tail's next will point to null, as it is the last node of the list tail.next = null; } else { //newNode will be added after tail such that tail's next will point to newNode tail.next = newNode; //newNode's previous will point to tail newNode.previous = tail; //newNode will become new tail tail = newNode; //As it is last node, tail's next will point to null tail.next = null; } } //display() will print out the nodes of the list public void display() { //Node current will point to head Node current = head; if (head == null) { System.out.println("List is empty"); return; } System.out.println("Nodes of doubly linked list: "); while (current != null) { //Prints each node by incrementing the pointer. System.out.print(current.data + " "); current = current.next; } } public static void main(String[] args) { Scanner scanner= new Scanner(System.in); DoublyLinkedList dList = new DoublyLinkedList(); //Add nodes to the list dList.addNode(new PhonebookData("Miqun Robinson", "908-239-2222")); dList.addNode(new PhonebookData("Michael Davis", "443-904-2332")); dList.addNode(new PhonebookData("Jackson Evers", "484-904-2222")); dList.addNode(new PhonebookData("Allison Whitehead", "650-455-2222")); dList.addNode(new PhonebookData("David Lamm", "484-885-2222")); dList.addNode(new PhonebookData("Zachary Whitehead", "484-223-1234")); if (sortedSet != null) for(Object node: sortedSet) { System.out.println(((PhonebookData) node).toString()); } //Displays the nodes present in the list dList.display(); System.out.println(" Starting search from head test..."); System.out.print("Enter search item (or q to quit):"); searchItem = scanner.nextLine(); while (!searchItem.equals("q")) { SortedSet sortedSet = dList.search(searchItem); if (sortedSet.size() != 0) { for (Object node : sortedSet) { System.out.println(((PhonebookData) node).toString()); } } else { System.out.println("No search results found..."); } System.out.print(" Enter search item (or q to quit):"); searchItem = scanner.nextLine(); } } } 

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!