I have a program where, if the user enters "1" then the "Assignment01" class will be called and if the user enters "14" then the "Assignment14" class will be called and so on.
Currently, I am using Switch Case Statement to call a function according to the user's number input like shown on the code. But what if there were 100 of classes which needs to be called per the user's input?
It will be really frustrating to have to create a case for calling every single class. So, is there another way to make it short and efficient?
For example:
// Assume user inputs "10" so 'userInput = 10'
String classVariable = "Assignment" + userInput + ".main(args)";
classVariable; // Result in like 'Assignment10.main(args);'
Unfortunately, this can't be done as that is a String but is there a similar way like to define that String into a class so it can be called like that?
EDIT: All I want is that when the user enters integer like say "30" then the class "Assignment30" should be called which can be done like "Assignment30.main(args);" through a switch case statement but I can't create every single case.
It would be better if I could put like say "Assignment+userInput+.main(args);" or something.
CODE:-
switch (userInput)
{
default:
AssignmentMain.errorLevel();
break;
case 1:
System.out.println();
Assignment01.main(args);
break;
case 2:
System.out.println();
Assignment02.main(args);
break;
case 3:
System.out.println();
Assignment03.main(args);
break;
case 4:
System.out.println();
Assignment04.main(args);
break;
case 5:
System.out.println();
Assignment05.main(args);
break;
}