There are two parts to this assignment.
First, you will need to provide the code for the data structure which handles all of the people. To do this, you will need to provide a class named CircularVector which implements the interface Circular, which I have provided for you.
Your implementation should include two instance variables: list, a vector to represent the circle, and current, an integer that specifies which element of the vector corresponds to the object in the circle currently being pointed at. Virtually all of the operations of the class are specified relative to the current element. For example next() moves the current element to refer to the next object (if the current object is last in the vector, then current must shift to the element at the beginning of the list: 0). The other operations should be clear from their names and the pre and post-conditions given for them. Notice that it is quite important to notice what happens to the current indicator after each operation. For example, after removeCurrent(), the current element becomes the element after the one removed (unless the list becomes empty, in which case there is no current element - indicated by setting current to -1).
Once you have implemented (and thoroughly tested) the CircularVector class, you will implement a class called Josephus, which will run a simulation of the Josephus problem. The class should provide a constructor that should allow a user to specify the size of the Josephus circle. The size of the circle should be > 0.
The class should also provide the following public methods:
public void reInit() // Pre: numMessengers in circle is > 0 // Post: circle of messengers is set up, with messengers named "1" to // "numMessengers" public void findMessenger(int skipNum); // Pre: skipNum >= 0. // Post: Messenger selected has been displayed on the screen; those // not selected have had their names printed in the order in which they // were excluded.
Plan your work carefully for this lab so that you can complete part one and begin part two in the lab. For this lab I will be checking design documents. Since I have provided classes with method headers for you, your design should consist of pseudocode for the method bodies.
In the same folder, you'll also find a pair of starter folders: one for the CircularVector class and one for the Josephus class. Copy these, and fill in the details. These folders contain the appropriate references to Java libraries. They also contain the Circular interface. You will need to provide the details for CircularVector.java and for Josephus.java. Before you test your Josephus class, be sure to add your definition of CircularVector to the Josephus project.
Back to:
andrea@cs.williams.edu