AP Computer Science :: Projects :: Josephus
Problem
There are different versions of the story of Josephus, but the one we will focus on entails Josephus trapped in a cave during the first century with a number of his fellow soldiers. It was considered a sin to commit suicide so, rurrounded by the Romans, the soldiers decided to stand in a circle and every third man would be killed by his fellow soldiers until one remained, who would then have to kill himself. Josephus, either by luck or the hand of God, remained alive at the end and decided to surrender to the Romans. Your task is to create a program that will model the Josephus problem and determine the correct place to stand in the circle given the number of people and the increment.
Instructions
- Download this project to start.
- You must use an ArrayList to store the number of each person standing in the circle. The numbers should start at 1.
- A constructor should add everyone to the list given the number of people in the circle.
- Create a method that removes a given person from the list until only 1 remains. It should return the number of the person left at the end as a String.
- Create good unit tests that use good test data. You may want to calculate the Josephus problem on paper a few times to determine your unit tests or use the above example.
Tips
- A for loop should be used for populating the ArrayList.
- A for loop wouldn't work very well for removing the people from the list. Try a while loop.