I'm trying to create a method(B) in one class(B) which, when invoked in a different class(A) : will ask a user for input and then invoke a method(A) in the class(A) which invoked it.
Kind of like this:
A:
public class ExampleClass {
public final int ACTIVITIES = 2;
public static void main(String[] args) {
Selector instance = new Selector();
instance.getActivity(ACTIVITIES);
}
public void Activity1(int input) {
// does stuff (Not pertinent)
}
public void Activity2(int input) {
// does other stuff (Not pertinent)
}
}
B:
public class Selector {
public void getActivity(int activities) {
int[] input = Selector.getInput(activities);
// run the appropriate method based on input[0] with the parameter input[1]
}
private static int[] getInput(int activities) {
// sets input[0] from user for Activity method (Not pertinent)
// sets input[1] from user for the Activity method's param (Not pertinent)
return input[];
}
}
The name of the method to be invoked is: "Activity"+Input[0]
hence the method names in ExampleClass
(ACTIVITIES
is used to limit the input to existing methods).
Recap: when ExampleClass
instantiates getActivity
: getActivity
needs to invoke either Activity1
or Activity2
with an int
parameter based on the user's input.
Aucun commentaire:
Enregistrer un commentaire