For our last List homework assignment, we are going to simulate a Beer flight that you can taste in different orders. To facilitate this we will use a circular doubly linked list to hold the beers. The list will implement the ListIterator interface. We’ll then use the Josephus problem to choose the order in which we taste the beers.
This is where we will put some of our classes for homework 06.
The next figure shows my New Class dialog.
Note: You should make sure the generic class entries agree. In this case they are all <E>.
Use the private inner DLinkedNode class like you did for homework H05.
You probably want to keep track of both head and tail since the list is circular.
In your CircularDoublyLinkedList you will need another private class that implements the ListIterator interface.
The iterator method will return a new instance of your private inner class.
In addition to the default constructor, your CircularDoublyLinkedList will need a constructor that takes an array and builds the list from the items in the array. You can loop over the items in the array adding them to the list.
Since this class is circular:
Use CircularDoublyLinkedListTest.java to test your linked list class.
The Josephus problem is named after Flavius Josephus, a historian and a reluctant leader of a revolt against the Roman Empire. When it appeared Josephus and his band were about to be captured, they chose to commit suicide rather than be enslaved. It is believed that the procedure they followed was for everyone in his band to form a circle and starting in a given direction, at a certain band member, count around the circle a predetermined number. When this number is reached, the person leaves the circle and commits suicide. The circle shrinks as the counting continues. When a person drops out of the circle, the count starts over with the next person.
Instead of people and committing suicide we are going to simulate tasting beers in a flight.
Create a JosephusBeerFlight class that implements the IBeerTasting interface.
The JosephusBeerFlight class must have a constructor that takes an array of Beers, the Beers in the flight.
The tasteBeers method should create a CircularDoublyLinkedList<Beer> and use the CircularDoublyLinkedList<Beer>.iterator() to choose the beers.
There are seven beers in the flight, numbered 1 through 7.
We are going to use the JosephusBeerFlightTest.java JUnit tests to evaluate your JosephusBeerFlight class for correctness.
Criterion | Excellent (100%) | Satisfactory (75%) | Borderline (50%) | Unsatisfactory (25%) | Poor (0) |
---|---|---|---|---|---|
Adherence to standards - 2 points Does it conform to standards in every detail? |
No errors. | Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. | Misses the point of the assignment. |
Breakdown (modular design) - 1 point Does it demonstrate good modular design? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Correctness of code - 4 points Does it work? Does it pass JUnit? |
Passes all tests. | Works for typical input, may fail for minor special cases. | Fails for typical input, for a minor reason. | Fails for typical input, for a major reason. | No. |
Documentation, and style - 2 points Is it clear and maintainable? Does it pass CheckStyle? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Efficiency of code - 1 point Does it use the Java features well? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
The assignment is due on Friday at 11:55pm. You may turn it in early.