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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education