Question: complete the missing code where it says //Your Code 1 Problem 2: Josephus class (35) Description: In the Josephus problem from antiquity, N people are

 complete the missing code where it says //Your Code 1 Problem
2: Josephus class (35) Description: In the Josephus problem from antiquity, N
complete the missing code where it says //Your Code

1 Problem 2: Josephus class (35) Description: In the Josephus problem from antiquity, N people are in dire straits and agree to the following strategy to reduce the population. They arrange themselves in a circle (at positions numbered from 0 to N - 1) and proceed around the circle, eliminating every Mth person until only one person is left. Legend has it that Josephus figured out where to sit to avoid being eliminated. Finish the Queue client Josephus.java that takes N and M from keyboard and prints out the order in which people are eliminated (and thus would show Josephus where to sit in the circle). Hint: you can make the Queue a virtual circle, so that every time, you can dequeue the first M-1 person, and enqueue them back to the end of the Queue, and therefore the Mth person will be the most front one on the Queue to dequeue out. Outputs: Your outputs should look something as follows. $ java Josephus Please enter a number for N indicating the total number of people: 7 Please enter a number M indicating the Mth person to be eliminated: 2 People will be eliminated in such a sequence: 1 3 5 0 4 2 6 package hw3; import java.util. public class Josephus { public ArrayList getJosephus (int n, int M){ // YOUR CODES return null; // for compilation. You need to change it. > public static void main(String[] args) { Josephus josephus = new Josephus(); Scanner input = new Scanner(System.in); System.out.print("Please enter a number for N indicating the total number of people: "); int N - input.nextInt(); System.out.print("Please enter a number for M indicating the Mth person to be eliminated: "); int M - input.nextInt(); input.close(); System.out.println("People will be deliminated in the following order: "); System.out.println(josephus.getJosephus (N, M))

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!