Due by the end of this meeting
The code uses an object of type TurnIterator. That class has not been provided. You need to write it. Its constructor takes a List and the TurnIterator allows the program to loop thru that list repeatedly until it has been reduced to one player.
The TurnIterator is a generic type that implements the Iterator interface.
next()
returns the next player.
It wraps around to the beginning
when it comes to the end of the given List.
hasNext()
tells whether there is a next player --
that is, another player different from the current one.
(It returns false only when the length of the List
has been reduced to one).
remove()
removes the last seen player.
Note that the List interface provides an iterator
method
that returns an iterator over the List,
but it doesn't behave the way we want it to.
But you can use the iterator it provides
to make your implementation.
In particular:
next()
,
it needs to check whether we've come to the end of the List,
and if so go back to the beginning.
hasNext()
,
it needs to check whether the size of the List has reduced to one.
remove()
,
it just needs to remove the last item it saw.
Figure out what instance variables/constants your TurnIterator needs, have the constructor set them, then implement the three methods.
You do not need to worry about Exceptions. If you do everything else properly, your code will throw the correct Exceptions automatically!
The program uses a random number generator, so it'll be different every time you run it. But you should see output similar to this:
For the purposes of the grading scheme,
the next()
method is the first activity,
and the constructor and other methods form the second activity.
Submit your TurnIterator class by the end of this recitation. (You do not need to submit your testing code; we know what your code is supposed to do!)
Your grade will be based on the following rubric:
Submit this/these files: