Two ways I can think of, the first is rather complicated but deals with a wide variety of potential user input, the second is simple using basic programming concepts but is limited in what it can do.
Use any of the methods described in this question. (I'm new. If referring to other answers like this is against the rules, just let me know, and please don't hate.)
Example code:
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class StackTester {
public static void main(String[] args) {
Method method = null;
// set methodName equal to the name of the method to be called
String methodName = "hi";
StackTester cls = new StackTester();
Class c = cls.getClass();
try {
method = c.getMethod(methodName, int.class);
System.out.println("method = " + method.toString());
}
catch (SecurityException e) {
System.out.println("fail1");
}
catch (NoSuchMethodException e) {
System.out.println("fail2");
}
try {
System.out.println(method.invoke(cls, 8));
}
catch (IllegalArgumentException e) {
}
catch (IllegalAccessException e) {
}
catch (InvocationTargetException e) {
}
}
public int hi(int x) {
return x;
}
}
The alternate method is to use a large series of if/else or switch/case in conjunction with Scanner reading user input to call all the method names you wish to call.
And just a suggestion for future reference: try some research on your own! I learned a lot just trying to answer this question.