public abstract class Operation
{
public double operatorA;
public double operatorB;
public abstract double getResult();
}
public class Add extends Operation
{
public double getResult()
{
double result;
result=operatorA+operatorB;
return result;
}
}
public class Subtract extends Operation
{
public double getResult()
{
double result;
result=operatorA-operatorB;
return result;
}
}
public class OperatorFactory
{
public static Operation createOperation(char operator)
{
Operation oper=null;
switch(operator)
{
case '+':oper=new Add(); break;
case '-':oper=new Subtract();break;
}
return oper;
}
}
import java.util.*;
public class Te