Question: Help Please, will thumbs up if works 100%! Has to follow all steps and include all that is required below: Learn to get a ListIterator

Help Please, will thumbs up if works 100%!

Has to follow all steps and include all that is required below:

Learn to get a ListIterator to access elements in a data structure

Instructions:

Create a main class with a name PracticeIteratorUse

Use an Iterator with two different types of data structure (ArrayList and LinkedList) and let them store values belonging to different data types (i.e. let ArrayList store integer and let LinkedList store Double data type)

Hint: Before you can use the two data structures above, you need to import the iterator, ArrayList and LinkedList from the java.util package.

Use a for loop for the two data structures:

To fill and print Elements in the ArrayList in ascending order. Let the elements be all the positive integers less than 200 that are divisible by both 3 and 4.

To fill and print Elements in the LinkedList in ascending order. Let the elements be all the numbers less than 200 that are divisible by both 2 and 3. (Remember this is a double data type when declaring the for loop variable name)

Create an iterator for each data structures you have created

And use hasNext inside a while loop, iterate through the data structures (i.e. ArrayList and LinkedList data structures) and print out their values or elements (Remember to print a space between the values).

Submission: submit the PracticeIteratorUse.java

BELOW IS WHAT OUTPUT SHOULD LOOK LIKE: Help Please, will thumbs up if works 100%! Has to follow all

This is what I have so far. I just dont know how to implement the required items: "while loops", "hasNext", "ListIterator" , "print elements in arrayList"

import java.util.Iterator;

import java.util.ArrayList;

import java.util.LinkedList;

import java.util.List;

public class UsingIterator {

public static void main(String[] args) {

/*

list aList = new ArrayList();

list iList = new LinkedList();

for( int i = 12; i

alist.add(i);

for( double i * 0; i

IteratoraListIterator = aList.iterator();

IteratoriListIterator = iList.iterator();

while(aListIterat.hasNext())

{

System.out.printf(" + ");

}

while(iListIterator.hasNext())

{

System.out.printf(" + ");

}

*/

System.out.printf("ArrayList Elements: %n");

for (int n = 0; n

{

if (n % 3 == 0) // divisible 3

{

if (n % 4 == 0) // divisible 4

System.out.print(n + " ");

} //end inner for loop

} // end outer for loop

System.out.printf("%n");

System.out.printf("%nLinkedList Elements%n");

for (double n = 0; n

{

if (n % 2 == 0) // divisible 2

{

if (n % 3 == 0) // divisible 3

System.out.print(n + " ");

} // end inner for loop

} // end outer for loop

} // end main method

}

--> make any changes neccessary to fill the required. Will thumbs up if perfect

Arrayist Elenents: 0 12 24 36 48 60 72 84 96 108 120 132 144 156 168 180 192 LinkedList Elenents: 0.0 6.0 12.0 18.0 24.0 30.0 36.0 42.0 48,0 54.0 60.0 66.0 72.0 78.0 84.0 90,0 96.0 LO2.0 108.0 L14.0 120.0 L26.0 132.0 138.0 144.0 150.0 156.0 162.0 168.0 174.0 100.0 186.0 192.0 198.0>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!