public override void addOpperand(Calc calc,Complex c)
 {
     //calc.Opperand1=calc.Total;
     //calc.Opperand2=c;
     calc.Total=c;
     calc.CurrentState=OpperandEnteredState.Singleton;
 }
 public override void addOpperand(Calc calc, Complex c)
 {
     //calc.CurrentState = ErrorState.Singleton;
     //throw new Exception("Cannot add opperand in opperand entered state");
     calc.setDisplay(c.ToString());
     calc.CurrentState = OpperandEnteredState.Singleton;
 }
 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 addOpperand(Calc calc, Complex c)
        {
            //just replace current w/ this
            calc.setDisplay(c.ToString());

            calc.CurrentState = OpperandEnteredState.Singleton;
        }
 public override void addOpperator(Calc calc, IBinOp op)
 {
     calc.pending_op = op;
     calc.setDisplay("");
     calc.CurrentState = OpperatorEntredState.Singleton;
     //calc.CurrentState=ErrorState.Singleton;
     //throw new Exception("cant add opperator in opperator entered state");
 }
 public override void enterDigit(Calc calc, char c)
 {
     Console.WriteLine("Start State: enter character " + c);
     calc.setDisplay("" + c);
     if ('0' != c)
     {
         calc.CurrentState = AccumState.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 addOpperand(Calc calc, Complex c)
        {
            //calc.Opperand1=calc.Total;
            //calc.Opperand2=c;
            calc.setDisplay(c.ToString());
            //			Complex result = calc.pending_op.compute(calc.Total, calc.Opperand2);
            //			calc.Total=result;
            //			calc.Opperand1=result;

            //why did I do this???
            //calc.pending_op=null;

            calc.CurrentState=OpperandEnteredState.Singleton;
            //calc.CurrentState=CompState.Singleton;
        }
        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 Calculate(Calc calc)
 {
     calc.CurrentState = (ErrorState.Singleton);
     throw new Exception ("cannot do calculation when no expressions have been entered --- in the start state");
 }
 public override void addOpperator(Calc calc, IBinOp op)
 {
     calc.CurrentState = ErrorState.Singleton;
     //throw new Exception ("cannot add opperator when an opperand has not been entered yet!");
 }
 public override void addOpperand(Calc calc, Complex c)
 {
     //calc.Total=new Complex(0,0);
     calc.setDisplay(c.ToString());
     calc.CurrentState = OpperandEnteredState.Singleton;
 }
 public abstract void addOpperator(Calc calc, IBinOp op);
Exemple #14
0
 public Form1()
 {
     InitializeComponent();
     calc = new Calc();
 }
 public override void Calculate(Calc calc)
 {
     throw new NotImplementedException ();
 }
 public override void enterDigit(Calc calc, char c)
 {
     throw new NotImplementedException();
 }
 public abstract void enterDigit(Calc calc, char c);
 public abstract void Calculate(Calc calc);
 public override void enterDigit(Calc calc, char c)
 {
     Console.WriteLine("Accumulate State: enter character " + c);
     calc.setDisplay(calc.getDisplay() + c);
     calc.CurrentState = AccumState.Singleton;
 }
 public override void addOpperator(Calc calc, IBinOp op)
 {
     //calc.Opperand1=calc.Total;
     calc.pending_op=op;
     calc.CurrentState=OpperatorEntredState.Singleton;
 }
 public override void Calculate(Calc calc)
 {
 }
 public override void enterDigit(Calc calc, char c)
 {
     //Complex c=Complex.Parse(calc.getDisplay());
     throw new NotImplementedException();
 }
 public override void enterDigit(Calc calc, char c)
 {
     Console.WriteLine("OpperatorEntredS State: enter character " + c);
     calc.setDisplay( c.ToString());
     calc.CurrentState = AccumState.Singleton;
 }
 public abstract void addOpperand(Calc calc, Complex c);