SlideShare a Scribd company logo
Class Diagram:
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 Banana Melon Orange }
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 boolean isEmpty()
The isEmpty method returns true of the linked list is empty, false otherwise.
3.
public void addElement(Object element)
The addElement adds the parameter element at the parameter in the linked list in alphabetical
order. For instance, if the linked list contains {Apple, Banana, Grape}, and a user tries to add
"Carrot", then it should be added as:
{Apple, Banana, Carrot, Grape}.
4.
public Object removeElement(int index)
The removeElement removes the string (Object) at the parameter index and returns it. Note that
this index starts with 0 just like array indices. For instance, if the linked list contains {Apple,
Banana, Carrot, Grape} and the parameter index is 3, then "Grape" should be remove. If the
parameter index is larger or smaller than the existing indices, it should throw an object of the
IndexOutOfBoundsException class (and the content of the linked list should remain unchanged).
5.
public Object getElement(int index)
The getElement searches the string (Object) at the parameter index and returns it. Note that this
index starts with 0 just like array indices. For instance, if the linked list contains {Apple, Banana,
Carrot, Grape} and the parameter index is 3, then "Grape" will be returned. If the parameter
index is larger or smaller than the existing indices, it should throw an object of the
IndexOutOfBoundsException class (and the content of the linked list should remain unchanged).
6.
public void searchAndReplace(Object oldString, Object newString)
The searchAndReplace method searches all occurrences of the first parameter string (object) in
the list, and replaces them with the second parameter string (object). If the parameter string does
not exist in the linked list, then the linked list content will not change.
7.
public int indexOfLast(Object searchString)
The indexOfLast searches the parameter string (object) with the largest index, and returns its
index. If the parameter string does not exist in the linked list, then it should return -1.
For instance, if the linked list contains { Apple Banana Banana Orange }, then after calling this
method with the parameter "Banana", then it should return 2, which is the index of later
Banana.
Solution
/* Posting Only the LinkedList.java where new methods have been added. */
public class LinkedList {
// nested class to represent a node
private class Node {
public Object data;
public Node next;
}
// only instance variable that points to the first node.
private Node first;
// Constructs an empty linked list.
public LinkedList() {
first = null;
}
// Returns the first element in the linked list.
public Object getFirst() {
if (first == null) {
NoSuchElementException ex = new NoSuchElementException();
throw ex;
} else
return first.data;
}
// Removes the first element in the linked list.
public Object removeFirst() {
if (first == null) {
NoSuchElementException ex = new NoSuchElementException();
throw ex;
} else {
Object element = first.data;
first = first.next; // change the reference since it's removed.
return element;
}
}
// Adds an element to the front of the linked list.
public void addFirst(Object element) {
// create a new node
Node newNode = new Node();
newNode.data = element;
newNode.next = first;
// change the first reference to the new node.
first = newNode;
}
// Returns an iterator for iterating through this list.
public ListIterator listIterator() {
return new LinkedListIterator();
}
/*********************************************************
* Add your methods here
*********************************************************/
// 1. toString()
// Override because we are overriding the Object class toString() method
@Override
public String toString() {
/*
* Since we need to add all the Nodes, use StringBuffer which is mutable
* unlike String which is Immutable. This increases efficiency.
*/
StringBuffer ansBuffer = new StringBuffer("{ ");
// add Nodes to the ans string ony if list is not empty
if (!isEmpty()) {
ListIterator listIteratorObject = listIterator();
while (listIteratorObject.hasNext()) {
ansBuffer.append(listIteratorObject.next() + " ");
}
}
ansBuffer.append("} ");
// ansBuffer.toString() returns a String object
return ansBuffer.toString();
}
// 2. isEmpty() method
public boolean isEmpty() {
// return this.first is null then return true else return false ( not
// Empty)
return this.first == null;
}
// 3. addElement(Object element)
public void addElement(String element) {
if (isEmpty()) {
addFirst(element);
} else {
// Empty String is also considered as a valid string since nothing
// has been mentioned about that case
ListIterator listIteratorObject = listIterator();
while (listIteratorObject.hasNext()) {
String current = (String) listIteratorObject.next();
if (element.compareTo(current) < 0) {
// change current string to new element
listIteratorObject.set(element);
//add current String after the current position
listIteratorObject.add(current);
return;
}
}
listIteratorObject.add(element);
}
}
// 4. Remove element at index removeIndex
public String removeElement(int removeIndex) {
// Holds the String which is Being removed
String removedString = null;
// If list is empty or removeIndex is negative, throw Exception
if (isEmpty() || removeIndex < 0) {
IndexOutOfBoundsException ex = new IndexOutOfBoundsException();
throw ex;
} else {
// Iterate to the removeIndex position
ListIterator listIteratorObject = listIterator();
while (removeIndex-- >= 0) {
if (listIteratorObject.hasNext()) {
removedString = (String) listIteratorObject.next();
} else {
// If no element left to iterate , throw Exception
IndexOutOfBoundsException ex = new IndexOutOfBoundsException();
throw ex;
}
}
// Remove the Node at that position
listIteratorObject.remove();
}
return removedString;
}
// 5. Same logic as above, only change is at the end do not remove the
// string
public String getElement(int getIndex) {
String getString = null;
if (isEmpty() || getIndex < 0) {
IndexOutOfBoundsException ex = new IndexOutOfBoundsException();
throw ex;
} else {
ListIterator listIteratorObject = listIterator();
while (getIndex-- >= 0) {
if (listIteratorObject.hasNext()) {
getString = (String) listIteratorObject.next();
} else {
IndexOutOfBoundsException ex = new IndexOutOfBoundsException();
throw ex;
}
}
}
return getString;
}
// 6. search original string and replace with newStr
public void searchAndReplace(String original, String newStr) {
ListIterator listIteratorObject = listIterator();
// Iterate up to the last Node
while (listIteratorObject.hasNext()) {
// If current Iterator object equals Original String ,set it to new
// String
if (original.equals(listIteratorObject.next())) {
listIteratorObject.set(newStr);
}
}
}
// 7. return LastIndexOf of the string str2.
public int indexOfLast(String str2) {
int lastIndex = -1;
int currentIndex = -1;
ListIterator listIteratorObject = listIterator();
// Iterate up to the last Node
while (listIteratorObject.hasNext()) {
// keep track of the current index
currentIndex++;
// Update Last Index if str2 matches current string
if (str2.equals(listIteratorObject.next()))
lastIndex = currentIndex;
}
return lastIndex;
}
/*********************************************************
* End of added methods
*********************************************************/
// nested class to define its iterator
private class LinkedListIterator implements ListIterator {
private Node position; // current position
private Node previous; // it is used for remove() method
// Constructs an iterator that points to the front
// of the linked list.
public LinkedListIterator() {
position = null;
previous = null;
}
// Tests if there is an element after the iterator position.
public boolean hasNext() {
if (position == null) // not traversed yet
{
if (first != null)
return true;
else
return false;
} else {
if (position.next != null)
return true;
else
return false;
}
}
// Moves the iterator past the next element, and returns
// the traversed element's data.
public Object next() {
if (!hasNext()) {
NoSuchElementException ex = new NoSuchElementException();
throw ex;
} else {
previous = position; // Remember for remove
if (position == null)
position = first;
else
position = position.next;
return position.data;
}
}
// Adds an element before the iterator position
// and moves the iterator past the inserted element.
public void add(Object element) {
if (position == null) // never traversed yet
{
addFirst(element);
position = first;
} else {
// making a new node to add
Node newNode = new Node();
newNode.data = element;
newNode.next = position.next;
// change the link to insert the new node
position.next = newNode;
// move the position forward to the new node
position = newNode;
}
// this means that we cannot call remove() right after add()
previous = position;
}
// Removes the last traversed element. This method may
// only be called after a call to the next() method.
public void remove() {
if (previous == position) // not after next() is called
{
IllegalStateException ex = new IllegalStateException();
throw ex;
} else {
if (position == first) {
removeFirst();
} else {
previous.next = position.next; // removing
}
// stepping back
// this also means that remove() cannot be called twice in a
// row.
position = previous;
}
}
// Sets the last traversed element to a different value.
public void set(Object element) {
if (position == null) {
NoSuchElementException ex = new NoSuchElementException();
throw ex;
} else
position.data = element;
}
} // end of LinkedListIterator class
} // end of LinkedList class

More Related Content

Similar to Class DiagramIn the Assignment #10, you are given three files Ass.pdf

For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
fashiongallery1
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docx
SHIVA101531
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
seoagam1
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
ezonesolutions
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
tesmondday29076
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Komlin1
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
ankit11134
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
aliracreations
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
deepakangel
 
Select three methods in the ObjectList class to work through algori.pdf
Select three methods in the ObjectList class to work through algori.pdfSelect three methods in the ObjectList class to work through algori.pdf
Select three methods in the ObjectList class to work through algori.pdf
aroraopticals15
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
alicesilverblr
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructuresmartha leon
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
rishabjain5053
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
aggarwalopticalsco
 

Similar to Class DiagramIn the Assignment #10, you are given three files Ass.pdf (20)

For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docx
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
 
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
 
Select three methods in the ObjectList class to work through algori.pdf
Select three methods in the ObjectList class to work through algori.pdfSelect three methods in the ObjectList class to work through algori.pdf
Select three methods in the ObjectList class to work through algori.pdf
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructures
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
 

More from xlynettalampleyxc

According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdfAccording to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
xlynettalampleyxc
 
Write a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdfWrite a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdf
xlynettalampleyxc
 
which represents the ground state for the N- ion i. w.ia ere sm.pdf
which represents the ground state for the N- ion  i. w.ia ere sm.pdfwhich represents the ground state for the N- ion  i. w.ia ere sm.pdf
which represents the ground state for the N- ion i. w.ia ere sm.pdf
xlynettalampleyxc
 
what is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfwhat is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdf
xlynettalampleyxc
 
What is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdfWhat is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdf
xlynettalampleyxc
 
WEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdfWEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdf
xlynettalampleyxc
 
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdfTwo astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
xlynettalampleyxc
 
The ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdfThe ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdf
xlynettalampleyxc
 
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdfThe output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
xlynettalampleyxc
 
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfThe end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
xlynettalampleyxc
 
Suppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfSuppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdf
xlynettalampleyxc
 
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdfSet up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
xlynettalampleyxc
 
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfSample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
xlynettalampleyxc
 
Practice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfPractice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdf
xlynettalampleyxc
 
Please, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfPlease, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdf
xlynettalampleyxc
 
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfPatient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
xlynettalampleyxc
 
Non-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfNon-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdf
xlynettalampleyxc
 
Name three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdfName three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdf
xlynettalampleyxc
 
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfInventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
xlynettalampleyxc
 
In December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfIn December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdf
xlynettalampleyxc
 

More from xlynettalampleyxc (20)

According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdfAccording to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
 
Write a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdfWrite a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdf
 
which represents the ground state for the N- ion i. w.ia ere sm.pdf
which represents the ground state for the N- ion  i. w.ia ere sm.pdfwhich represents the ground state for the N- ion  i. w.ia ere sm.pdf
which represents the ground state for the N- ion i. w.ia ere sm.pdf
 
what is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfwhat is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdf
 
What is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdfWhat is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdf
 
WEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdfWEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdf
 
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdfTwo astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
 
The ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdfThe ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdf
 
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdfThe output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
 
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfThe end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
 
Suppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfSuppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdf
 
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdfSet up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
 
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfSample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
 
Practice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfPractice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdf
 
Please, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfPlease, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdf
 
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfPatient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
 
Non-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfNon-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdf
 
Name three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdfName three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdf
 
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfInventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
 
In December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfIn December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdf
 

Recently uploaded

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

Class DiagramIn the Assignment #10, you are given three files Ass.pdf

  • 1. Class Diagram: 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 Banana Melon Orange } 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 boolean isEmpty() The isEmpty method returns true of the linked list is empty, false otherwise. 3. public void addElement(Object element) The addElement adds the parameter element at the parameter in the linked list in alphabetical order. For instance, if the linked list contains {Apple, Banana, Grape}, and a user tries to add "Carrot", then it should be added as: {Apple, Banana, Carrot, Grape}. 4. public Object removeElement(int index) The removeElement removes the string (Object) at the parameter index and returns it. Note that this index starts with 0 just like array indices. For instance, if the linked list contains {Apple, Banana, Carrot, Grape} and the parameter index is 3, then "Grape" should be remove. If the parameter index is larger or smaller than the existing indices, it should throw an object of the IndexOutOfBoundsException class (and the content of the linked list should remain unchanged). 5. public Object getElement(int index) The getElement searches the string (Object) at the parameter index and returns it. Note that this index starts with 0 just like array indices. For instance, if the linked list contains {Apple, Banana,
  • 2. Carrot, Grape} and the parameter index is 3, then "Grape" will be returned. If the parameter index is larger or smaller than the existing indices, it should throw an object of the IndexOutOfBoundsException class (and the content of the linked list should remain unchanged). 6. public void searchAndReplace(Object oldString, Object newString) The searchAndReplace method searches all occurrences of the first parameter string (object) in the list, and replaces them with the second parameter string (object). If the parameter string does not exist in the linked list, then the linked list content will not change. 7. public int indexOfLast(Object searchString) The indexOfLast searches the parameter string (object) with the largest index, and returns its index. If the parameter string does not exist in the linked list, then it should return -1. For instance, if the linked list contains { Apple Banana Banana Orange }, then after calling this method with the parameter "Banana", then it should return 2, which is the index of later Banana. Solution /* Posting Only the LinkedList.java where new methods have been added. */ public class LinkedList { // nested class to represent a node private class Node { public Object data; public Node next; } // only instance variable that points to the first node. private Node first; // Constructs an empty linked list. public LinkedList() { first = null; } // Returns the first element in the linked list. public Object getFirst() { if (first == null) { NoSuchElementException ex = new NoSuchElementException();
  • 3. throw ex; } else return first.data; } // Removes the first element in the linked list. public Object removeFirst() { if (first == null) { NoSuchElementException ex = new NoSuchElementException(); throw ex; } else { Object element = first.data; first = first.next; // change the reference since it's removed. return element; } } // Adds an element to the front of the linked list. public void addFirst(Object element) { // create a new node Node newNode = new Node(); newNode.data = element; newNode.next = first; // change the first reference to the new node. first = newNode; } // Returns an iterator for iterating through this list. public ListIterator listIterator() { return new LinkedListIterator(); } /********************************************************* * Add your methods here *********************************************************/ // 1. toString() // Override because we are overriding the Object class toString() method @Override public String toString() { /*
  • 4. * Since we need to add all the Nodes, use StringBuffer which is mutable * unlike String which is Immutable. This increases efficiency. */ StringBuffer ansBuffer = new StringBuffer("{ "); // add Nodes to the ans string ony if list is not empty if (!isEmpty()) { ListIterator listIteratorObject = listIterator(); while (listIteratorObject.hasNext()) { ansBuffer.append(listIteratorObject.next() + " "); } } ansBuffer.append("} "); // ansBuffer.toString() returns a String object return ansBuffer.toString(); } // 2. isEmpty() method public boolean isEmpty() { // return this.first is null then return true else return false ( not // Empty) return this.first == null; } // 3. addElement(Object element) public void addElement(String element) { if (isEmpty()) { addFirst(element); } else { // Empty String is also considered as a valid string since nothing // has been mentioned about that case ListIterator listIteratorObject = listIterator(); while (listIteratorObject.hasNext()) { String current = (String) listIteratorObject.next(); if (element.compareTo(current) < 0) { // change current string to new element listIteratorObject.set(element); //add current String after the current position listIteratorObject.add(current);
  • 5. return; } } listIteratorObject.add(element); } } // 4. Remove element at index removeIndex public String removeElement(int removeIndex) { // Holds the String which is Being removed String removedString = null; // If list is empty or removeIndex is negative, throw Exception if (isEmpty() || removeIndex < 0) { IndexOutOfBoundsException ex = new IndexOutOfBoundsException(); throw ex; } else { // Iterate to the removeIndex position ListIterator listIteratorObject = listIterator(); while (removeIndex-- >= 0) { if (listIteratorObject.hasNext()) { removedString = (String) listIteratorObject.next(); } else { // If no element left to iterate , throw Exception IndexOutOfBoundsException ex = new IndexOutOfBoundsException(); throw ex; } } // Remove the Node at that position listIteratorObject.remove(); } return removedString; } // 5. Same logic as above, only change is at the end do not remove the // string public String getElement(int getIndex) { String getString = null; if (isEmpty() || getIndex < 0) {
  • 6. IndexOutOfBoundsException ex = new IndexOutOfBoundsException(); throw ex; } else { ListIterator listIteratorObject = listIterator(); while (getIndex-- >= 0) { if (listIteratorObject.hasNext()) { getString = (String) listIteratorObject.next(); } else { IndexOutOfBoundsException ex = new IndexOutOfBoundsException(); throw ex; } } } return getString; } // 6. search original string and replace with newStr public void searchAndReplace(String original, String newStr) { ListIterator listIteratorObject = listIterator(); // Iterate up to the last Node while (listIteratorObject.hasNext()) { // If current Iterator object equals Original String ,set it to new // String if (original.equals(listIteratorObject.next())) { listIteratorObject.set(newStr); } } } // 7. return LastIndexOf of the string str2. public int indexOfLast(String str2) { int lastIndex = -1; int currentIndex = -1; ListIterator listIteratorObject = listIterator(); // Iterate up to the last Node while (listIteratorObject.hasNext()) { // keep track of the current index currentIndex++;
  • 7. // Update Last Index if str2 matches current string if (str2.equals(listIteratorObject.next())) lastIndex = currentIndex; } return lastIndex; } /********************************************************* * End of added methods *********************************************************/ // nested class to define its iterator private class LinkedListIterator implements ListIterator { private Node position; // current position private Node previous; // it is used for remove() method // Constructs an iterator that points to the front // of the linked list. public LinkedListIterator() { position = null; previous = null; } // Tests if there is an element after the iterator position. public boolean hasNext() { if (position == null) // not traversed yet { if (first != null) return true; else return false; } else { if (position.next != null) return true; else return false; } } // Moves the iterator past the next element, and returns // the traversed element's data.
  • 8. public Object next() { if (!hasNext()) { NoSuchElementException ex = new NoSuchElementException(); throw ex; } else { previous = position; // Remember for remove if (position == null) position = first; else position = position.next; return position.data; } } // Adds an element before the iterator position // and moves the iterator past the inserted element. public void add(Object element) { if (position == null) // never traversed yet { addFirst(element); position = first; } else { // making a new node to add Node newNode = new Node(); newNode.data = element; newNode.next = position.next; // change the link to insert the new node position.next = newNode; // move the position forward to the new node position = newNode; } // this means that we cannot call remove() right after add() previous = position; } // Removes the last traversed element. This method may // only be called after a call to the next() method. public void remove() {
  • 9. if (previous == position) // not after next() is called { IllegalStateException ex = new IllegalStateException(); throw ex; } else { if (position == first) { removeFirst(); } else { previous.next = position.next; // removing } // stepping back // this also means that remove() cannot be called twice in a // row. position = previous; } } // Sets the last traversed element to a different value. public void set(Object element) { if (position == null) { NoSuchElementException ex = new NoSuchElementException(); throw ex; } else position.data = element; } } // end of LinkedListIterator class } // end of LinkedList class