Question
Please Solve this error! import library.IntNode; public class intrusionDetectorClass { static IntNode head = null; public static void main(String[] args) { System.out.println(Prj1 is running. );
Please Solve this error!
import library.IntNode;
public class intrusionDetectorClass {
static IntNode head = null; public static void main(String[] args) { System.out.println("Prj1 is running. "); head = new IntNode(13, 230185386, head); head.displayNodeData(head); removeDuplicate(13); if (head != null) head.displayNodeData(head); else { System.out.print("The linked list is empty. "); System.out.print(" "); } addNodeInOder(13, 308329763); head.displayNodeData(head); removeDuplicate(14); head.displayNodeData(head); addNodeInOder(14, 248041794); head.displayNodeData(head);
removeDuplicate(14); head.displayNodeData(head); addNodeInOder(14, 295106305); head.displayNodeData(head); removeDuplicate(15); head.displayNodeData(head); addNodeInOder(15, 325615905); head.displayNodeData(head); removeDuplicate(16); head.displayNodeData(head); addNodeInOder(16, 652976466); head.displayNodeData(head); removeDuplicate(17); head.displayNodeData(head); addNodeInOder(17, 847897267); head.displayNodeData(head);
removeDuplicate(17); head.displayNodeData(head); addNodeInOder(17, 927847798); head.displayNodeData(head); System.out.println("End of run. "); } // Precondition: head refers the first node in the linked list, or is null when the linked list is empty. // The linked list contains at least one element. // Postcondition: If the linked list contains a node with sequenceNumber equal to target, // then that node is removed from the linked list. Otherwise, no changes are made. public static IntNode removeDuplicate(int target) { if (head == null) return head; System.out.println("Running removeDuplicate() on target " + target + " "); IntNode previous = null; if (target == head.getsequenceNumber()) { head = head.getLink(); } else previous = head.findPrevious(head, target); if (previous != null) previous.removeNodeAfter(); return head; } // Precondition: head refers the first node in the linked list, or is null when the linked list is empty. // Postcondition: A new node with attributes target and data is created. Target serves as sequenceNumber. // The new node is added to the linked list so that its sequenceNumber preserves the ascending order of the linked list // relative to the sequenceNumber. public static IntNode addNodeInOder(int target, int data) { IntNode previous = null; System.out.println("Running addNodeInOrder() on target " + target + " and data " + data + " "); if (head == null) { head = new IntNode(target, data, head); return head; } if (target < head.getsequenceNumber()) head = new IntNode(target, data, head); else previous = head.locatePredecessor(head, target); if (previous != null) previous.addNodeAfter(target, data); return head; }
}
public class IntNode { private int sequenceNumber; private int data; private IntNode link;
//Default constructor public IntNode() { sequenceNumber = 0; data = 0; link = null; }
//Constructor with parameters public IntNode(int sequenceNumber, int data, IntNode link) { this.sequenceNumber = sequenceNumber; this.data = data; this.link = link; }
public void setSequenceNumber(int sequenceNumber) { this.sequenceNumber = sequenceNumber; }
public void setData(int data) { this.data = data; }
public void setLink(IntNode link) { this.link = link; }
public int getsequenceNumber() { return sequenceNumber; }
public int getData() { return data; }
public IntNode getLink() { return link; }
//Finds the node that has the target sequenceNumber public IntNode findNode(IntNode head, int target) { IntNode position = head; int sequenceNumberAtPosition;
while (position != null) { sequenceNumberAtPosition = position.sequenceNumber; if (sequenceNumberAtPosition == target) return position; position = position.link; } return null; }
//Finds the node that is before the node that contains the target sequenceNumber public IntNode findPrevious(IntNode head, int target) { IntNode position = head; IntNode previousPosition = head; int sequenceNumberAtPosition;
while (position != null) { sequenceNumberAtPosition = position.sequenceNumber; if (sequenceNumberAtPosition == target) return previousPosition; previousPosition = position; position = position.link; } return null; }
//Finds the node that is before the node that contains the target sequenceNumber public IntNode locatePredecessor(IntNode head, int target) { IntNode position = head; IntNode previousPosition = null;
while (position != null) { if (position.getsequenceNumber() >= target) { return previousPosition; }
previousPosition = position; position = position.getLink(); }
return previousPosition; }
//Removes the node after this node public void removeNodeAfter() { link = link.link; }
//Adds a node after this node public void addNodeAfter(int sequenceNumber, int data) { link = new IntNode(sequenceNumber, data, link); }
//Displays the data in the current node public void displayNodeData(IntNode head) { IntNode position = head;
while (position != null) { System.out.println("sequenceNumber: " + position.sequenceNumber + " data: " + position.data); position = position.link; } System.out.print(" "); } }
Print:
Prj1 is running.
Node: (13, 230185386) Running removeDuplicate() on target 13
The linked list is empty. Running addNodeInOrder() on target 13 and data 308329763
Node: (13, 308329763) Running removeDuplicate() on target 14
Node: (13, 308329763) Running addNodeInOrder() on target 14 and data 248041794
Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet. at library.IntNode.locatePredecessor(IntNode.java:59) at IntrusionDetectorClass.addNodeInOder(IntrusionDetectorClass.java:107) at IntrusionDetectorClass.main(IntrusionDetectorClass.java:28) C:\Users\kyley\AppData\Local\NetBeans\Cache\12.6\executor-snippets un.xml:111: The following error occurred while executing this line: C:\Users\kyley\AppData\Local\NetBeans\Cache\12.6\executor-snippets un.xml:68: Java returned: 1 BUILD FAILED (total time: 1 second)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
The error message youre encountering javalangUnsupportedOperationException indicates that a method o...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started