Пример #1
0
 public override void addOpperator(Calc calc, IBinOp op)
 {
     calc.Total=Complex.Parse(calc.getDisplay());
     calc.pending_op = op;
     calc.setDisplay("");
     calc.CurrentState = OpperatorEntredState.Singleton;
 }
 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");
            }
        }
Пример #4
0
 public override void enterDigit(Calc calc, char c)
 {
     Console.WriteLine("Accumulate State: enter character " + c);
     calc.setDisplay(calc.getDisplay() + c);
     calc.CurrentState = AccumState.Singleton;
 }