import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
public static void main(String[] args)
throws NoSuchMethodException,InvocationTargetException, IllegalAccessException {
Calculator calculator = new Calculator();

Integer returnValue = Action.run(
1,
Integer.class,
calculator,
Calculator.class.getDeclaredMethod(
"plus",
Integer.class,
Integer.class
),
5,
10);
System.out.println("returnValue : " + returnValue);

Integer staticReturnValue = Action.run(
1,
Integer.class,
null,
Calculator.class.getDeclaredMethod(
"minus",
Integer.class,
Integer.class),
5,
10);
System.out.println("staticReturnValue : " + staticReturnValue);

}

static class Calculator {
public Integer plus(Integer a, Integer b) {
System.out.println(a + " + " + b + " = " + (a + b));
return a + b;
}

public static Integer minus(Integer a, Integer b) {
System.out.println(a + " - " + b + " = " + (a - b));
return a - b;
}
}

static class Action {
public static <T> T run(
double percentage,
Class<T> returnClass,
Object object,
Method method,
Object... args)
throws InvocationTargetException, IllegalAccessException {
double random = Math.random();
if (random < percentage) {
return (T) method.invoke(object, args);
}
return null;
}
}
}


대충 확률로 메서드 실행 시켜주는 건데 


생각해보니까 그냥 메서드마다 확률로 실행시켜주는 걸 넣는 게 나을 듯 싶긴한 데 몰루겠다 ㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇ