Question: Programing project 5.5 The Josephus Problem is a famous mathematical puzzle that goes back to ancient times. There are many stories to go with the

Programing project 5.5

The Josephus Problem is a famous mathematical puzzle that goes back to ancient times. There are many stories to go with the puzzle. One is that Josephus was one of a group of Jews who were about to be captured by the Romans. Rather than be enslaved, they chose to commit suicide. They arranged themselves in a circle and, starting at a certain person, started counting off around the circle. Every nth person had to leave the circle and commit suicide. Josephus decided he didnt want to die, so he arranged the rules so he would be the last person left. If there were (say) 20 people, and he was the seventh person from the start of the circle, what number should he tell them to use for counting off? The problem is made much more complicated because the circle shrinks as the counting continues. Create an application that uses a circular linked list (like that in Programming Project 5.3) to model this problem. Inputs are the number of people in the circle, the number used for counting off, and the number of the person where counting starts (usually 1). The output is the list of persons being eliminated. When a person drops out of the circle, counting starts again from the person who was on his left (assuming you go around clockwise). Heres an example. There are seven people numbered 1 through 7, and you start at 1 and count off by threes. People will be eliminated in the order 4, 1, 6, 5, 7, 3. Number 2 will be left.

YOU MUST USE THIS MAIN in order to solve this problem!!! YoU MUST USE it

public static void main(String[] args) throws IOException

{

int j, nPlayers, nSkips, startNo;

CircList theList = new CircList(); // make list

putText("Enter the number of players: ");

nPlayers = getInt();

for(j=nPlayers; j>0; j--) // number 1, 2, ...

theList.insert(j);

putText("Players: ");

theList.display();

putText("Enter the number of spaces to skip: ");

nSkips = getInt();

putText("Enter the the starting player's number: ");

startNo = getInt();

theList.find(startNo); // set current to start

while(theList.getSize() > 1) // until one player left

{

System.out.print("Counting " + nSkips +

" places from player ");

theList.peek().display();

System.out.println("");

putText("Press Enter: ");

getString();

for(j=0; j

theList.step();

Link eliminee = theList.peek();

System.out.println("Player number *** " +

eliminee.iData + " *** will be eliminated");

theList.delete();

putText("Players: ");

theList.display();

}

putText("The last player remaining is ");

theList.display();

} // end main()

THe output must be like this. The output must be this below in format and content (DO NOT POST IF ITS NOT THIS OUTPUT)

Enter the number of players: 7

Players: 1 2 3 4 5 6 7

Enter the number of spaces to skip: 3

Enter the starting player's number: 7

Counting 3 places from player 7

Press Enter:

Player number *** 3 *** will be eliminated

Players: 4 5 6 7 1 2

Counting 3 places from player 4

Press Enter:

Player number *** 7 *** will be eliminated

Players: 1 2 4 5 6

Counting 3 places from player 1

Press Enter:

Player number *** 5 *** will be eliminated

Players: 6 1 2 4

Counting 3 places from player 6

Press Enter:

Player number *** 4 *** will be eliminated

Players: 6 1 2

Counting 3 places from player 6

Press Enter:

Player number *** 6 *** will be eliminated

Players: 1 2

Counting 3 places from player 1

Press Enter:

Player number *** 2 *** will be eliminated

Players: 1

The last player remaining is 1

Process completed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!