I am trying to solve the josephus problem, but with a bit of a twist when it comes to syntax. The user needs to be able to enter data in the following format:
java Josephus 3 java.util.ArrayList < test.txt
the 3 is used as the number of people skipped in the problem itself, but the rest is where it becomes complicated, the user is to enter the name of a class that extends a list, as well as use the '<' symbol to enter the file to be used, only problem is I have no earthly idea how to access the contents of this file and reflect the classname to create an object
edit: for clarification, the test.txt file contains names, and will be taken into the list as strings.
I am currently using the following line for reflection:
List list = (List) Class.forName(args[1]).getDeclaredConstructor().newInstance();
and the following lines for reading from the file:
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
list.add(scan.next());
}
Aucun commentaire:
Enregistrer un commentaire