L06a

Due by the end of this meeting

Starter Files:


SUBMIT   /   Submission Summary

The Iterator Interface

Activities 1 and 2
I have provided you with a program (Lab06a) that plays a game with dice. Each player rolls a pair of dice. If the player rolls 7, they're eliminated from the game. Play continues until only one player remains.

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.

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:

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:

Alpha rolled 11. Bravo rolled 7. Bravo is eliminated! Charlie rolled 6. Delta rolled 4. Echo rolled 7. Echo is eliminated! Alpha rolled 5. Charlie rolled 3. Delta rolled 5. Alpha rolled 12. Charlie rolled 4. Delta rolled 6. Alpha rolled 12. Charlie rolled 7. Charlie is eliminated! Delta rolled 11. Alpha rolled 12. Delta rolled 7. Delta is eliminated! The winner is Alpha!

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:


SUBMIT   /   Submission Summary