public override void Calculate(Calc calc) { Complex total = calc.pending_op.compute(calc.Total, Complex.Parse(calc.getDisplay())); calc.setDisplay(total.ToString()); calc.Total = total; calc.CurrentState = CompState.Singleton; //calc.CurrentState=ErrorState.Singleton; //throw new Exception("you cant do a calculation right after you add an opperator, need another opperand"); }
public override void Calculate(Calc calc) { if (calc.pending_op != null) { Complex opperand = Complex.Parse(calc.getDisplay()); Complex total = calc.pending_op.compute(calc.Total, opperand); //calc.Opperand1=total; calc.Total = total; calc.setDisplay(total.ToString()); calc.CurrentState = CompState.Singleton; } else { calc.CurrentState=ErrorState.Singleton; // throw new Exception("cannot do calculation w/o pending opperator"); } }
public override void addOpperator(Calc calc, IBinOp op) { calc.Total = Complex.Parse(calc.getDisplay()); calc.pending_op=op; calc.CurrentState=OpperatorEntredState.Singleton; }