Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

pecifically, the following methods must be implemented in the LinkedList class:

ID: 3554460 • Letter: P

Question

pecifically, the following methods must be implemented in the LinkedList class:
(You should utilize listIterator() method already defined in the LinkedList class to obtain its LinkedListIterator object, and use the methods in the LinkedListIterator to traverse from the first element to the last element of the linked list to define the following methods.)

    public String toString()

The toString method should concatenate strings in the linked list, and return a string of the following format:

{ Orange Banana Melon Apple }

Thus it starts with "{" and ends with "}", and there is a space between strings and "{" or "}". If the list is empty, it returns "{ }" with a space in between.

public int size()

The size method returns the number of strings that the linked list contains at the time when this method is called.


    public int searchElement(Object element)

The searchElement method returns the index of the element (string). If the element does not exist, then it returns -1.


    public Object getElement(int index)

The getElement method returns an element at the given index (passed as its parameter). If the parameter index is larger or smaller than the existing indices, it should throw an object of the type IndexOutOfBoundsException class.


    public void addElement (int index, Object element)

The addElement adds the element at the specified index. The element at the index and any elements at the later indices will be shifted towards the end of the list. If the parameter index is larger or smaller than the existing indices, it should throw an object of the IndexOutOfBoundsException class.


    public Object removeElement(int index)

The removeElement removes the element at th specified index and the removed element should be returned. If the parameter index is larger or smaller than the existing indices, it should throw an object of the IndexOutOfBoundsException class.


public void appendStringAfter(Object str1, Object str2)

The appendStringAfter method searches the first occurrence of the first parameter string (str1), and appends (add) the second parameter string (str2) after the first string occurrence.
If the linked list does not contain a string str1, then the second parameter string is added at the end of the linked list.


public int countOccurrences (Object element)

The countOccurrences method counts how many times the object appears in the linked list and returns it. It returns 0 if the element does not exist in the linked list

Test your LinkedList class with the given Assignment10.java file.
It is recommended to test boundary cases such as empty linked list, when it contains only one element, when adding/removing at the beginning or at the end of the linked list.

Explanation / Answer

( Done EXACTLY following the mentioned Specifications )

Here is the link to code : http://ideone.com/KkTlS8

Just copy and pasted in file LinkedList.java and Run :)