//运算的接口
interface Operation
{ //计算的方法
int oper(int a,int b) throws Exception;
}
//工厂 根据符号得到一个Operation对象
class OperationFactory
{
public static Operation getInstance(char c){
Operation op=null;
switch(c){
case '+'p=new Add();break;
case '-'p=new Sub();break;
case '*'p=new Mul();break;
case '/'p=new Div();break;
}
return op;
}
}
class Add implements Operation
{
public int oper(int a,int b){
return a+b;
}
}
class Sub implements Operation
{
public int oper(int a,int b){
return a-b;
}
}
class Mul implements Operation
{
public int oper(int a,int b){
return a*b;
}
}
class Div implements Operation
{
public int oper(int a,int b) throws Exception{