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 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 enterDigit(Calc calc, char c) { Console.WriteLine("Error State: enter character " + c); calc.setDisplay("" + c); if ('0' != c) { calc.CurrentState = AccumState.Singleton; } }
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 enterDigit(Calc calc, char c) { Console.WriteLine("OpperatorEntredS State: enter character " + c); calc.setDisplay( c.ToString()); calc.CurrentState = AccumState.Singleton; }
public override void addOpperand(Calc calc, Complex c) { //calc.Total=new Complex(0,0); calc.setDisplay(c.ToString()); calc.CurrentState = OpperandEnteredState.Singleton; }