java - Is there some way to call a class which is defined by String or a similar way? -


i have program where, if user enters "1" "assignment01" class called , if user enters "14" "assignment14" class called , on.

currently, using switch case statement call function according user's number input shown on code. if there 100 of classes needs called per user's input?

it frustrating have create case calling every single class. so, there way make short , efficient?

for example:

// assume user inputs "10" 'userinput = 10' string classvariable = "assignment" + userinput + ".main(args)";  classvariable; // result in 'assignment10.main(args);' 

unfortunately, can't done string there similar way define string class can called that?

edit: want when user enters integer "30" class "assignment30" should called can done "assignment30.main(args);" through switch case statement can't create every single case.

it better if put "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;  } 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -