In this lab, you will review and create three iterators and submit the assignment through Gradescope.
Download the following files:
The file iterators.zip contains all of these files in single download.
Take a few minutes to read over the file BackScanner.java
to make sure you understand
how it works. You can test it using the provided driver (IteratorDriver.java
)
Complete SkipScanner.java
so that it conforms to the provided
javadoc comments. You can test your iterator with the
SkipScannerTest
JUnit tests.
Make a copy of your working SkipScanner.java
class to a new file named
SkipScannerGeneric.java
. Change the SkipScannerGeneric
class
so that instead of accepting an array of Strings it will accept an array
containing any type of object.
Complete NGramScanner.java
so that it conforms to the provided
javadoc comments. You can test your iterator with the
NGramScannerTest
JUnit tests.
Submit the following files through Gradescope:
SkipScanner.java
NGramScanner.java
SkipScannerGeneric.java
If you have extra time, implement a PrimesGenerator
class that
implements Iterable<Integer>
. Your class should make it possible to
iterate over prime numbers as in the following example:
public static void main(String[] args) {
for (int p : new PrimesGenerator(10)) {
System.out.println(p);
}
}
In this case, the expected output would be the first ten primes:
2
3
5
7
11
13
17
19
23
29
There is nothing to submit for this exercise.