Due by the end of Thursday, February 15
To set up the league, the fans need to take turns picking a player (we want each fan's team to have different players). That means we need to run thru the list of fans giving that fan a chance to choose a player. There would be as many rounds as necessary to allow all available players to be picked.
Of course if the same order of fans was used every round, then the first player in the list would get an unfair advantage. There are multiple ways to try to make things fairer, one of which is the "snake" (or serpentine) order: the order of selection reverses every round. So if we have three fans, Amy, Bina and Chris, then the order of selection in each round would be:
I have provided you with a program (Lab06b) that carries out a fantasy league draft using that method. The program uses an object of type SnakeIterator. That class has not been provided. You need to write it. Its constructor takes a List and the SnakeIterator allows the program to go back and forth thru that list repeatedly until all players have been selected.
The SnakeIterator is a generic type that implements the Iterator interface.
next()
returns the next fan.
It reverses order
when it gets all the way thru the given List.
hasNext()
tells whether there is a next fan --
which there will be
unless the List is empty.
Note that the List interface provides a listIterator
method
that returns a ListIterator 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 it's going forward thru the List
or backward,
and also whether it's come to the "end" of whichever direction it's headed.
If it has reached the "end",
it needs to reverse direction.
Then
it returns the next
element (if going forward)
or the previous
element (if going in reverse).
hasNext()
,
it needs to check whether the List is empty.
Figure out what instance variables/constants your SnakeIterator needs, have the constructor set them, then implement the two 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:
Note how it runs from Alpha to Delta, and then from Delta to Alpha, and repeating that pattern until all "players" have been chosen. (The players are the numbers, and each fan (a word) is choosing the highest available number.)
For the purposes of the grading scheme,
the next()
method is the first activity,
and the constructor and hasNext
method form the second activity.
Submit your SnakeIterator 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: