How do I write a method to find the last soldier remaining given any number of soldiers initially? Read the names of the soldiers in order from the standard input stream. There will be one or more names. All names are separated by white space, i.e, no name contains white space. The step size K≥1 is the first command-line argument. The K−1 is the number soliders to skip. If K=1, then one skips no soldiers and removes the first soldier, the second soldier, and so on. (So if K were one, then the last soldier remaining is the last soldier in the list/circle.) It is important that the program use a list, i.e., the Java interface java.util.List so that we can compare list implementations. The method to find the last remaining solder must be programmed in such as way that any object implementing java.util.List is appropriate input data. The name of the class to use for the circle of soldiers is the second command line argument. The main program must run the experimnet ten times (on the same list). Then print the average time the method takes to compute the answer. Include only the time the method takes, not the time to fill the list with names. Run a series of expirements and compare ArrayList and LinkedList, like in the previous lab. Always use the same K=7. Run the program on both kinds of lists ten times--with list sizes 400, 800, 1200, ..., 4000 soldiers. Create a scatter chart of the run time (vertical axis) versus the size of the list (horizontal axis). Use blue triangles markers for the LinkedList data and red squares for the ArrayList. Plot your data with the best trend line as in the preivous lab. Sample 1 For the K=4 java Josephus 4 java.util.ArrayList Veronica David Kathryn Jonathan Diane Amber Alicia Tara William Mark The output looks something like this: Last soldier: Diane. Time: PT0.000059472S The program has only one line of output to the standard output stream as shown above. The time is to be printed out in ISO-8601 duration format.
How do I write a method to find the last soldier remaining given any number of soldiers initially? Read the names of the soldiers in order from the standard input stream. There will be one or more names. All names are separated by white space, i.e, no name contains white space. The step size K≥1 is the first command-line argument. The K−1 is the number soliders to skip. If K=1, then one skips no soldiers and removes the first soldier, the second soldier, and so on. (So if K were one, then the last soldier remaining is the last soldier in the list/circle.)
It is important that the
The main program must run the experimnet ten times (on the same list). Then print the average time the method takes to compute the answer. Include only the time the method takes, not the time to fill the list with names.
Run a series of expirements and compare ArrayList and LinkedList, like in the previous lab. Always use the same K=7. Run the program on both kinds of lists ten times--with list sizes 400, 800, 1200, ..., 4000 soldiers. Create a scatter chart of the run time (vertical axis) versus the size of the list (horizontal axis). Use blue triangles markers for the LinkedList data and red squares for the ArrayList. Plot your data with the best trend line as in the preivous lab.
Sample 1
For the K=4
java Josephus 4 java.util.ArrayList
Veronica David
Kathryn Jonathan
Diane Amber
Alicia Tara
William Mark
The output looks something like this:
Last soldier: Diane. Time: PT0.000059472S
The program has only one line of output to the standard output stream as shown above. The time is to be printed out in ISO-8601 duration format.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images