{"id":49077,"date":"2021-09-10T18:11:47","date_gmt":"2021-09-10T18:11:47","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/09\/10\/i-use-intellij-please-show-the-output-and-also-simple-explain-the-code-you-write-thank-you\/"},"modified":"2021-09-10T18:11:47","modified_gmt":"2021-09-10T18:11:47","slug":"i-use-intellij-please-show-the-output-and-also-simple-explain-the-code-you-write-thank-you","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/09\/10\/i-use-intellij-please-show-the-output-and-also-simple-explain-the-code-you-write-thank-you\/","title":{"rendered":"I use intelliJ please show the output and also simple explain the code you write ,thank you"},"content":{"rendered":"<p>java. <br \/>\/\/Add a file header comment or a class header comment to your work.package assign3_template;\/** * Assign 3 template. Implement more methods in List interface. *\/public class SimpleLinkedList { \/\/&#8212;&#8212;-Start of Assign 3 &#8212;&#8212;&#8211;\/ \/\/2.1.2 Coding Requirements \/\/You can call other methods to complete a method. \/\/You can also add private methods, and then call these methods \/\/ to complete a method required in this assignment. \/\/You are NOT allowed to add or remove data fields to\/from SimpleLinkedList class. \/\/You are NOT allowed to change the definition of Node class. \/\/2.1.1 What Code to Add \/\/&#8212;&#8211;Required &#8212;&#8212;&#8212;&#8212;&#8212;\/\/ \/\/Remove the first occurrence of the specified item from this linked list. \/\/ If success, return true. Otherwise, return false. public boolean removeByValue(int item) { \/\/add your own code \/\/Hint: \/\/ call your indexOf(&#8230;) to locate the item, \/\/ convert the following in SingleLinkedList \/\/ private E removeFirst() \/\/ private Node getNode(int index) \/\/ private E removeAfter(Node node) \/\/Hint: if you implement this from scratch, remember to save: \/\/ predecessor node reference \/\/ current node reference return false; } \/\/add item to be at [index]; \/\/ if index is [0, size-1], insert item between [index-1] and [index] \/\/ if index is size, append item to the end of this linked list. public void add(int index, int item) { \/\/add your own code \/\/Hint: \/\/convert the following in SingleLinkedList \/\/ public void add(int index, E item) \/\/ public void addFirst(E item) \/\/ private Node getNode(int index) \/\/ private void addAfter(Node node, E item) } \/\/Get the integer item at the specified position and return the integer value. \/\/If the index is not valid, throw an exception or print an error message \/\/ and return Integer.MIN_VALUE. public int get(int index) { \/\/add your own code \/\/Hint: \/\/convert the following in SingleLinkedList \/\/ public E get(int index) \/\/ private Node getNode(int index) return 2; } \/\/Search this linked list for the first occurrence of the specified integer: item. \/\/If the item is found, return its index. Otherwise return -1. public int indexOf(int item) { \/\/add your own code \/\/Hint: \/\/use a looping like the one in toString() \/\/in addition, add a counter, \/\/ increment the counter for each element checked \/\/can use size for loop control. return -1; } \/\/Find out if the specified integer: item is in this linked list. \/\/ Returns true if yes, false otherwise. public boolean contains(int item) { \/\/add your own code \/\/Hint: \/\/can either call indexOf(&#8230;) \/\/ or directly search for the item using a loop like the one in toString() return false; } \/\/return how many integers are in this linked list public int size() { \/\/add your own code \/\/Hint: this is actually a getter return 0; } \/\/&#8212;&#8211;Bonus &#8212;&#8212;&#8212;&#8212;&#8212;\/\/ \/\/Remove the item at the specified position from this linked list and \/\/ return the removed item. \/\/If the index is not valid, throw an exception or print an error message \/\/ and return Integer.MIN_VALUE. public int removeByIndex(int index) { \/\/Add your own code \/\/Hint: \/\/verify that index is valid \/\/convert the following in SingleLinkedList \/\/ private Node getNode(int index) \/\/ private E removeAfter(Node node) \/\/Hint: if you implement this from scratch, remember to save: \/\/ predecessor node reference \/\/ current node reference return 2; } \/\/&#8212;&#8212;-End of Assign 3 &#8212;&#8212;&#8211;\/ \/\/Following code were covered in Lec#6. \/\/Don&#8217;t change them. \/\/Nested class Node, enclosing class: SimpleLinkedList private static class Node { private int data; private Node next; private Node(int data) { this.data = data; next = null; } \/\/constructor used to create a Node that has a following neighbor private Node(int dataNew, Node nextNew) { data = dataNew; next = nextNew; } @Override public String toString() { return data &#8220;&#8221;; \/\/&#8221;10&#8243; } } \/\/the reference to the first Node in this linked list. private Node head; \/\/the size of this linked list private int size; \/\/create an empty linked list public SimpleLinkedList() { head = null; size = 0; } \/\/append newItem public boolean add(int newItem) { Node temp = new Node(newItem); if (head == null) { \/\/empty list head = temp; } else { \/\/non-empty list \/\/locate last node Node current = head; \/\/start with the first node while (current.next != null) { \/\/check if current node is not the last node current = current.next; \/\/move on to the next node on the list } current.next = temp; \/\/append the new node immediately following the current node } size ; return true; } \/\/return a string that contains all integers (in the original sequence) in the linked list. @Override public String toString() { String result = &#8220;&#8221;; \/\/result string Node current = head; \/\/start with first Node while (current != null) { \/\/check if there is still nodes remaining result = current.data; \/\/add the integer in current Node to the result string result = &#8220;&#8211;&gt;&#8221;; current = current.next; \/\/move on to the next Node } return result; }}<\/p>\n<p> \/\/\/<br \/> \/\/File: SimpleLinkedListTest.java. \/\/Add a file header comment or a class header comment to your work.package assign3_template;\/** * Assign 3 Template. * Testing different methods (successful and failed calls) * *\/public class SimpleLinkedListTest { public static void main(String[] args) { \/\/2.2 Revise SimpleLinkedListTest \/\/create an empty singly linked list of int values \/\/append some integers \/\/test each implemented method using at least 2 calls: \/\/ successful call, e.g. call indexOf(..) and pass an existing integer \/\/ failed call, e.g. call indexOf(..) and pass a non-existing integer \/\/You can reuse some of the code below given to you in Lec#6. \/\/&#8211;Following code were given in Lec#6 &#8211;\/\/ \/\/create an empty list SimpleLinkedList numbers = new SimpleLinkedList(); \/\/append 3 integers numbers.add(10); numbers.add(20); numbers.add(30); \/\/dump the contents in the list in the original order System.out.println(numbers); \/\/or use: \/\/System.out.println(numbers.toString()); } }<\/p>\n<p> this is the simple output:<br \/> 10&#8211;&gt;20&#8211;&gt;30&#8211;&gt;<br \/> 10&#8211;&gt;40&#8211;&gt;20&#8211;&gt;30&#8211;&gt;<br \/> 4<br \/> 40<br \/> true<br \/> false<br \/> 3<br \/> -1<br \/> true50 not in the list!<br \/> false<br \/> 40<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java. \/\/Add a file header comment or a class header comment to your work.package assign3_template;\/** * Assign 3 template. Implement more methods in List interface. *\/public class SimpleLinkedList { \/\/&#8212;&#8212;-Start of Assign 3 &#8212;&#8212;&#8211;\/ \/\/2.1.2 Coding Requirements \/\/You can call other methods to complete a method. \/\/You can also add private methods, and then call [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10],"class_list":["post-49077","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-writing"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/49077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=49077"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/49077\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=49077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=49077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=49077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}