Helper Class that works with the Custom Interface

master
sgoudham 4 years ago
parent 2af4b69da3
commit 0931d91922
No known key found for this signature in database
GPG Key ID: EF51A29A50FB754C

@ -0,0 +1,29 @@
public class DynamicHelper {
private final MathProcessing[] handlers;
public DynamicHelper(MathProcessing[] handlers) {
this.handlers = handlers;
}
public void process(String statement) {
String[] parts = statement.split(MathProcessing.SEPARATOR);
String keyword = parts[0];
double leftVal = Double.parseDouble(parts[1]);
double rightVal = Double.parseDouble(parts[2]);
MathProcessing theHandler = null;
for(MathProcessing handler : handlers) {
if(keyword.equalsIgnoreCase(handler.getKeyWord())) {
theHandler = handler;
break;
}
}
double result = theHandler.doCalculation(leftVal, rightVal);
if (theHandler.doFormatting() != null)
System.out.println(theHandler.doFormatting());
else
System.out.println("result = " + result);
}
}
Loading…
Cancel
Save