Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago