CSci 2101 Labs 7. Java linked list.

Due Wednesday, October 19th at 11:59pm

35 points

The lab will be done in pairs or groups of three.

Task 1: Random integers iterator.

Write a class RandomInts that produces n random integers between min (inclusive) and max (exclusive) as an iterator. This means that you can use it like this:


RandomInts myInts = new RandomInts(1, 101, 8);
for (int i: myInts){
   System.out.println(i);
}


The loop should give you 8 pseudo-random numbers uniformly distributed between 1 and 100 (inclusive).

The iterator in the class must implement Iterator<Integer>. The constructor for RandomInts takes 3 integers: the lower bound min, the upper bound max, and the number of random numbers needed n. Then each call to next() in the iterator returns a random integer between min and max (inclusive). hasNext() returns true until n is reached, at which point it returns false. Note that different iterators for the same RandomInts class would generate different random integers.

Use only one instance of Random so that the numbers are guaranteed to be uniformly distributed. This means that Random should be an instance variable of the iterator, not a local variable in a method.

Task 2: Queue implementation (code reuse)

Write a class OurQueueImplementation that implements the OurQueue interface. Create a file in Eclipse, make your class implement the interface, and then use Eclipse QuickFix to add unimplemented methods. Make sure that element and remove return a type E and the iterator returns Iterable<E>.

Then write testing code for the queue in a file TestOurQueue. Write tests for all methods (including a for-each loop that tests the iterator), then start filling in the code. We will talk in class about the easiest way of implementting a queue.

Carefully follow method description. Make sure that exceptions are thrown as appropriate. Use try/catch blocks in your testing code to check for exceptions.

How to submit:

Send me your code (with answers to Eclipse questions). CC your partner if you worked in a pair.


CSci 2101 course web site.