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

Objectives: After finishing the lab5 part 2, you can: -Understand how to access

ID: 3802909 • Letter: O

Question

Objectives:

After finishing the lab5 part 2, you can:

-Understand how to access the nodes in the singly

-linked list structure when applying 4 operations: insert, delete, fetch and update

-Apply Iterator to Linked list to traverse the structures.

-Learn how to use the Java LinkedList


Requirement Statement: Create the project SP2017_LAB5 then write the application named SP2017_LinkedListDemo_yourLastName that allows users to select one of the following tasks of Linked list to manage the list of Cars or Motocycles

1. Singly Linked List

2. Singly Linked List with Iterator

3. Java Linked List with Iterator <<<<<<<<< This is the one below i need help with


After finishing with one type of Linked List, allow users to select another type until users want to exit

For the Java LinkedList with iterator

-INSERT: Allow users to insert cars or motocycles at least 4 vehicles or until users want to stop.For each car or motocycle, ask users to enter information that needs to create an object then insert it to the Java Linked List Display all the nodes in the Java Linked List

FETCH -Fetch and display 2 first cars or motocycles on the list

UPDATE -Fetch the node at location 2 -Change its color -Update the node with new color to the Java Linked List Display all the nodes in the Java Linked List

DELETE -move forward the iterator one location then delete the car or motocycle at the current iterator position - Display all the nodes in the Java Linked List

Explanation / Answer

LinkedList<String> linkedList = new LinkedList<String>();

linkedList.add("BMW");

linkedList.add("AUDI");

linkedList.add("JAGUAR");

linkedList.add("BENZ");

Three Types of iterating given below

// ListIterator

System.out.println("ListIterator Approach:");

ListIterator<String> listIterator = linkedList.listIterator();

while (listIterator.hasNext()) {

System.out.println(listIterator.next());

}

System.out.println(" Loop Approach:");

// Normall for loop approach

for (int i = 0; i < linkedList.size(); i++) {

System.out.println(linkedList.get(i));

}

// forEach

System.out.println(" Java8 Approach: ");

linkedList.forEach(System.out::println);

}

INSERT - linkedList.add(object);

FETCH - linkedList.get(index);

UPDATE - linkedList.set(index,object);

DELETE - linkedList.remove(index);