Question: I need to fix this errors.. This are the two file codes: import java.util.Optional; public class LinkedListNode { private V value; private LinkedListNode next; public
I need to fix this errors..
This are the two file codes:
import java.util.Optional;
public class LinkedListNode
private V value;
private LinkedListNode
public LinkedListNode(V value, LinkedListNode
this.value = value;
this.next = next;
}
public Optional
return Optional.ofNullable(next);
}
public V getValue() {
return value;
}
public LinkedListNode setValue(V value) {
this.value = value;
return this;
}
public LinkedListNode setNext(LinkedListNode
this.next = next;
return this;
}
@Override
public String toString() {
return "LinkedListNode{" +
"value=" + value +
'}';
}
}
================================
import java.util.Optional;
public class LinkedList
private LinkedListNode
public LinkedList() {
head = null;
}
public void addFront(V item) {
this.head = new LinkedListNode(item, head);
}
public void deleteFront() {
Optional
this.head = firstNode.flatMap(LinkedListNode::getNext).orElse(null);
firstNode.ifPresent(n -> n.setNext(null));
}
public Optional
Optional
while (node.filter(n -> n.getValue() != item).isPresent()) {
node = node.flatMap(LinkedListNode::getNext);
}
return node;
}
public void addAfter(LinkedListNode
aNode.setNext(new LinkedListNode(item, aNode.getNext().orElse(null)));
}
// write your code here
public String toString()
{
String s = "[";
LinkedListNode temp = head;
while(temp != null)
{
s += String.valueOf(temp.getValue());
if(temp != null)
{
s += ",";
}
}
s += "]";
return s;
}
public static void main(String[] args) {
LinkedList
list.addFront("Isabel");
list.addFront("Ruth");
list.addFront("Karl");
list.addFront("John");
System.out.println(list.find("Isabel"));
System.out.println(list.find("Ruth"));
System.out.println(list.find("Karl"));
System.out.println(list.find("John"));
System.out.println(list.find("James"));
list.deleteFront();
System.out.println(list.find("John"));
list.addFront("Oliver");
System.out.println(list.find("Ruth"));
list.addAfter(list.find("Ruth").get(), "Sam");
System.out.println(list.toString());
LinkedListNode
}
}
I believe the main problem is in the LinkedList.java where the public String toString() is, here are the errors:



10.00 out of 30.00 Use a while loop to traverse the linked list to add the nodes to print to the console. Wrap the list of nodes in opening and closing brackets separated by commas: [node1, node2, node3] . 1 out of 3 checks passed. Review the results below for more details. Checks Code Pattern Complete toString() contains a while loop Unit Test Incomplete toString() returns the nodes of the linked list as a String > Unit Test Incomplete toString() works as expected with the provided main() Unit Test Incomplete toString() returns the nodes of the linked list as a String Build Status Build Succeeded Test Output Test Contents @Test public void toStringUnitTest2() { LinkedList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
