$29
In this lab, you will implement several clients of the List data structure using iterators. You will first write two simple methods to iterate over lists, then you will implement a version of the Sieve of Eratosthenes (see Lab 7 for full details).
Your TA will overview the use of iterators.
Exercise
• er the TA’s lesson, complete the following steps:
1. Download the provided code and read it over.
2. In the class ListUtils within the cs445.lab8 package, write the generic method
which prints the contents
of a List. You should rely en rely on iterators; don not use the List’s .get() method.
Test that your method works properly.
3. Within the same class, write the method static void removeShortStrings(ListInterface<String> list, int limit) , which removes all strings shorter than limit . Again, rely only on iterators for element access, and test that your method works. Do not use the List’s .get() or .remove(int) methods.
4. Within cs445.lab8.SieveofEratosthenes , implement method ListInterface<Integer> primesUpTo(int max) . This method should use the Sieve
of Eratosthenes to build and return a list of integers containing all of the primes up to max . Use instances from Lab 7 to test your program. Again, do not use .get() or .remove(int) from List in your method.
Conclusion
In this lab, you implemented several methods, including a sieving technique for determining all of the prime integers up to a threshold. More importantly, you prac ced using iterators