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

In the Assignment #10, you are given three files Assignment10.java, LinkedList.j

ID: 3813160 • Letter: I

Question

In the Assignment #10, you are given three files Assignment10.java, LinkedList.java, and ListIterator.java. You will need to add additional methods in the LinkedList class in the LinkedList.java file. The LinkedList will be tested using strings only.

Specifically, 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 class to traverse from the first element to the last element of the linked list to define the following methods.)

1.
    public String toString()

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

{ Apple Melon Orange Banana }

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.

2.
    public int size()

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

3.
    public void addElement(Object element, int index)

The addElement adds the parameter element at the parameter 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.

4.
    public String findSmallest( )

The findSmallest method should return the string that is smallest lexically among the strings stored in the linked list. It should return null (null pointer) if the linked list is empty.

5.
    public void searchAndReplace(Object first, Object second)

The searchAndReplace method should search and replace all strings that match with the first parameter "first" with the second parameter "second". If the linked list does not contain a string that matches with the first parameter, then the linked list content should not change after calling this method.

6.
    public void searchAndRemove(Object toBeRemoved)

The searchAndRemove method should search and remove all strings that match with the first parameter "toBeRemoved". If the linked list does not contain a string that matches with the first parameter, then the linked list content should not change after calling this method.

7.
    public void reverseFirstSome(int howMany)

The reverseFirstSome method should reverse the number of strings located at the beginning, specified by the parameter integer. For instance, if the parameter "howMany" is 3, then the first 3 strings in the linked list should be reversed.
If the number "howMany" is 0 or less, then the linked list content will not change, and if it is same or more than the size of the linked list, then the entire linked list content will be reversed.

(This file does not need to be modified)

(This file does not need to be modified)

(It needs to be modified)

input 1:
A
Grape
0
L
A
Melon
0
L
C
A
Apple
2
L
A
Peach
0
L
A
Banana
1
L
C
D
L
A
Potato
-1
L
A
Kiwi
5
L
A
Avocado
10
L
A
Lemon
0
L
Q

input 2:
L
C
A
Banana
10
L
A
Apple
0
L
A
Potato
1
A
Grape
2
A
Melon
0
A
Kiwi
1
A
Lemon
2
A
Guava
3
A
Orange
2
A
Olive
3
A
Pear
4
L
T
3
L
T
5
L
T
-3
L
T
1000
L
Q

input 3:
C
R
Orange
Apple
L
S
Orange
L
A
Apple
6
L
A
Orange
0
A
Tomato
1
A
Apple
0
A
Potato
1
A
Orange
2
L
R
Orange
Kiwi
L
R
Kiwi
Lemon
L
R
Tomato
Potato
L
R
Potato
Watermelon
L
S
Apple
L
C
Q

input 4:
L
D
C
A
Tomato
0
A
Mango
0
A
Banana
2
A
Guava
2
L
C
D
A
Lime
2
L
R
Apple
Tomato
L
R
Lime
Guava
L
S
Guava
L
Q


output 1:
Choice       Action
------       ------
A       Add String
C       Count its Size
D       Find Smallest
L       List Strings
Q       Quit
R       Replace Strings
S       Remove Strings
T       Reverse Strings from Beginning
?       Display Help

What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Grape }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Melon Grape }
What action would you like to perform?
The size of the linked list is 2
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Melon Grape Apple }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Peach Melon Grape Apple }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Peach Banana Melon Grape Apple }
What action would you like to perform?
The size of the linked list is 5
What action would you like to perform?
The smallest string is Apple
What action would you like to perform?
{ Peach Banana Melon Grape Apple }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
The index is out of bounds
What action would you like to perform?
{ Peach Banana Melon Grape Apple }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Peach Banana Melon Grape Apple Kiwi }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
The index is out of bounds
What action would you like to perform?
{ Peach Banana Melon Grape Apple Kiwi }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Lemon Peach Banana Melon Grape Apple Kiwi }
What action would you like to perform?

output 2:
Choice       Action
------       ------
A       Add String
C       Count its Size
D       Find Smallest
L       List Strings
Q       Quit
R       Replace Strings
S       Remove Strings
T       Reverse Strings from Beginning
?       Display Help

What action would you like to perform?
{ }
What action would you like to perform?
The size of the linked list is 0
What action would you like to perform?
Please enter a string to add:
Please enter its index:
The index is out of bounds
What action would you like to perform?
{ }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Apple }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Melon Kiwi Orange Olive Pear Lemon Guava Apple Potato Grape }
What action would you like to perform?
Please enter a number of elements to reverse from the beginning:
What action would you like to perform?
{ Orange Kiwi Melon Olive Pear Lemon Guava Apple Potato Grape }
What action would you like to perform?
Please enter a number of elements to reverse from the beginning:
What action would you like to perform?
{ Pear Olive Melon Kiwi Orange Lemon Guava Apple Potato Grape }
What action would you like to perform?
Please enter a number of elements to reverse from the beginning:
What action would you like to perform?
{ Pear Olive Melon Kiwi Orange Lemon Guava Apple Potato Grape }
What action would you like to perform?
Please enter a number of elements to reverse from the beginning:
What action would you like to perform?
{ Grape Potato Apple Guava Lemon Orange Kiwi Melon Olive Pear }
What action would you like to perform?

output 3:
Choice       Action
------       ------
A       Add String
C       Count its Size
D       Find Smallest
L       List Strings
Q       Quit
R       Replace Strings
S       Remove Strings
T       Reverse Strings from Beginning
?       Display Help

What action would you like to perform?
The size of the linked list is 0
What action would you like to perform?
Please enter a string to replace from the linked list:
Please enter a string to replace with:
What action would you like to perform?
{ }
What action would you like to perform?
Please enter a string to remove from the linked list:
What action would you like to perform?
{ }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
The index is out of bounds
What action would you like to perform?
{ }
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Apple Potato Orange Orange Tomato }
What action would you like to perform?
Please enter a string to replace from the linked list:
Please enter a string to replace with:
What action would you like to perform?
{ Apple Potato Kiwi Kiwi Tomato }
What action would you like to perform?
Please enter a string to replace from the linked list:
Please enter a string to replace with:
What action would you like to perform?
{ Apple Potato Lemon Lemon Tomato }
What action would you like to perform?
Please enter a string to replace from the linked list:
Please enter a string to replace with:
What action would you like to perform?
{ Apple Potato Lemon Lemon Potato }
What action would you like to perform?
Please enter a string to replace from the linked list:
Please enter a string to replace with:
What action would you like to perform?
{ Apple Watermelon Lemon Lemon Watermelon }
What action would you like to perform?
Please enter a string to remove from the linked list:
What action would you like to perform?
{ Watermelon Lemon Lemon Watermelon }
What action would you like to perform?
The size of the linked list is 4
What action would you like to perform?

output 4:
Choice       Action
------       ------
A       Add String
C       Count its Size
D       Find Smallest
L       List Strings
Q       Quit
R       Replace Strings
S       Remove Strings
T       Reverse Strings from Beginning
?       Display Help

What action would you like to perform?
{ }
What action would you like to perform?
There is no element in the linked list
What action would you like to perform?
The size of the linked list is 0
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Mango Tomato Guava Banana }
What action would you like to perform?
The size of the linked list is 4
What action would you like to perform?
The smallest string is Banana
What action would you like to perform?
Please enter a string to add:
Please enter its index:
What action would you like to perform?
{ Mango Tomato Lime Guava Banana }
What action would you like to perform?
Please enter a string to replace from the linked list:
Please enter a string to replace with:
What action would you like to perform?
{ Mango Tomato Lime Guava Banana }
What action would you like to perform?
Please enter a string to replace from the linked list:
Please enter a string to replace with:
What action would you like to perform?
{ Mango Tomato Guava Guava Banana }
What action would you like to perform?
Please enter a string to remove from the linked list:
What action would you like to perform?
{ Mango Tomato Banana }
What action would you like to perform?

Assignment 10 +main(StringO): void printMenuo void LinkedList first Node +LinkedList() getFirst(): Object tremove First(): Object +addFirst object): void rtlistlteratoro: Listlterator +toString (0:String size():int +addElement(Object, int) void tfindSmallesto:String searchAndReplace(Object,Object):void tsearchAndRemove(Object):void +reversed FirstSome(int) void You will need to implement only the methods in red. LinkedListIterator position: Node -previous: Node +LinkedListlterator0 +has Next():boolean +next0: Object +add(Object): void +remove(): void +set (Object):void Node data: Object +next:Node Arizona State University CSE205, Assignment 10, Spring 2017 ListIterator +has Nexto: boolean +next(0:Object +add(Object): void +remove(): void +set objecto void

Explanation / Answer

Paste your text here and click on "Next" to observe this text redact do it's issue.

haven't any text to check? haven't any text to check? Click "Select Samples".public category List<E>
personal Node first;
personal Node last;
personal long length;
  
personal category Node
  

/**
* A generic inner ListIterator category that implements the
* ListIteratorAPI. it's used as a indicator to traverse the list.
*/
personal category ListIterator implements ListIteratorAPI<E>
personal Node position; // the node on the left of the iterator
personal Node previousPosition; // the previous iterator position
personal Boolean isAfterNext;
personal Boolean isAfterPrevious;
  
/**
* Constructs associate iterator that points to the front
* of the coupled list.
*/
public ListIterator()
  

/**
* Resets the iterator's previousPosition to its current position,
* resets the iterator's current position to the node on the proper of
* its current position (moves the iterator, within the forward direction,
* past the node on the right), and returns the knowledge worth in the node
* that the iterator simply omitted.
*/
public E next() throws ListException
methodology.
}
  
/**
* Returns true if there's a node on the proper of the iterator
* position; otherwise, returns false.
*/
public Boolean hasNext()
come back 1st != null;
else
come position.next != null;
}
  
/**
* Returns true if the iterator position isn't null;
* otherwise, returns false.
*/
public Boolean hasPrevious()
methodology.
}


  
/**
* Inserts a replacement node on the left of the iterator and resets
* the iterator position to the present inserted node.
*/
public void add(E data)
methodology.
}

/**
* Removes the last node omitted by the iterator during a decision to
* either next or previous.
* Throws associate exception if take away isn't known as directly once a
* decision to either next or previous.
*/
public void remove() throws ListException
methodology.
}

/**
* Replaces the info worth within the node on the left of the iterator
* with the input file worth.
*/
public void set(E data) throws ListException
  
else
  
length++;
}

/**
* Adds an element to the end of the linked list.
* @param data the data value to add
*/
public void addLast(E data)
  
  
/**
* Removes the first element in the linked list.
* @return the removed element
*/
public E removeFirst() throws ListException
  
length--;
return data;
}
  
/**
* Removes the last element in the linked list.
* @return the removed element
*/
public E removeLast() throws ListException
  
  
/**
* Returns the first element in the linked list.
* @return the first element in the linked list
*/
public E getFirst() throws ListException
  
  
/**
* The number of elements in this list.
* @return the length of this list.
*/
public long size()
  
  
/**
* @return a string representation of the elements of this list
* in the format [e0, e1, ..., en-2, en-1], where each ei is a data
* value in the list and e0 is the data value in the first node
* and en-1 is the data value in the last node. It returns [] if this
* stack is empty.
*/   
public String toString()
  
  
  
}


package list;

public interface ListIteratorAPI<E>
{
/**
* Resets the iterator's previousPosition to its current position,
* resets the iterator's current position to the node on the right of
* its current position (moves the iterator, in the forward direction,
* past the node on the right), and returns the info worth within the node
* that the iterator just passed over.
*/
E next() throws ListException;
  
/**
* Resets the iterator's previousPosition to its current position,
* resets the iterator's current position to the node on the
* left of its current position (moves the iterator, in the backward
* direction, past the node on the left), and returns the data value
* within the node that the iterator simply omitted.
*/
E previous() throws ListException;
  
/**
* Returns true if the iterator position isn't null;
* otherwise, returns false.
*/
Boolean hasNext();
  
/**
* Returns true if there's a node on the left of the iterator
* position; otherwise, returns false.
*/
Boolean hasPrevious();
  
/**
* Inserts a replacement node on the left of the iterator and resets
* the iterator position to the present inserted node.
*/
void add(E data);
  
/**
* Removes the last node omitted by the iterator during a decision to
* either next or previous.
* Throws associate exception if take away isn't known as directly once a
* decision to either next or previous.
*/
void remove() throws ListException;
  
/**
* Replaces the info worth within the node on the left of the iterator
* with the input file worth.
*/
void set(E data) throws ListException;
  
}



package list;

import java.util.NoSuchElementException;

public category ListException extends NoSuchElementException

}