Answered step by step
Verified Expert Solution
Question
1 Approved Answer
roblem Description: In computer science and mathematics, the Josephus problem is a theoretical problem related to a certain counting-out game. Here's the basic, if not
roblem Description: In computer science and mathematics, the Josephus problem is a theoretical problem related to a certain counting-out game. Here's the basic, if not somewhat gruesome, story People are standing in a circle waiting to be executed. A number is selected at random (the skip count). Counting begins with person number 1 and proceeds around the circle. The person at the skip count is executed. Yikes! The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping to the same number person, until only one person remains, and is freed Graduation is coming up, our future is bright, so we want to be that last person! Given the number of people in the group and number to be skipped, we want to choose the position in the initial circle to avoid execution. This is probably best illustrated with an example. If there are 10 people (numbered 1 through 10) and the group has decided to eliminate every 3rd (skip count 3), you would expect the sequence to go as follows: 1st round: 1 2 (3) 4 5 (6) 7 8 (9) 10. Persons 3, 6, and 9 were "eliminated". .2nd round: 1 (2) 45 (7) 8 10. Persons 2 and 7 were "eliminated. . 3rd round: (1) 45 (8) 10. Persons 1 and 8 were "eliminated". . 4th round: 4 (5) 10. Person 5 was "eliminated". . 5th round: 4 (10). Person 10 was "eliminated" Therefore, the last remaining person will be #4. That's where we want to be Use a class that implements java.util.Queue> (for example LinkedList) to implement your solution. You must access your object through the Queue interface. Do not use any other methods from LinkedList. Continue playing this game (?) until the user is done (see the example output) You will need to ask the user for two numbers, the number of members in the group, and the skip count. If either user input is not an integer, make sure you catch this exception and prompt the user again. Notes: Do not create these classes in a package. For Eclipse, this means using the default package Turn in only your Java source files
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started