private void HandleOperatorPressed(object sender, OperatorPressedEventArgs e) { entry = Entry.Integer; decimalCount = 1; switch (e.Operator) { case Operator.Add: if (parenClosed) { this.view.Display = parenStack[0].Result.ToString("0.####"); AddOperation parenAdd = new AddOperation(); parenAdd.LeftOperand = parenStack[0]; current = parenAdd; mode = Mode.Replace; parenClosed = false; break; } AddOperation add = new AddOperation(); add.LeftOperand = storedOperation; current = add; mode = Mode.Replace; break; case Operator.Subtract: if (parenClosed) { this.view.Display = parenStack[0].Result.ToString("0.####"); SubtractOperation parenSubtract = new SubtractOperation(); parenSubtract.LeftOperand = parenStack[0]; current = parenSubtract; mode = Mode.Replace; parenClosed = false; break; } SubtractOperation subtract = new SubtractOperation(); subtract.LeftOperand = storedOperation; current = subtract; mode = Mode.Replace; break; case Operator.Multiply: if (parenClosed) { MultiplyOperation parenMultiply = new MultiplyOperation(); parenMultiply.LeftOperand = parenStack[0]; current = parenMultiply; mode = Mode.Replace; parenClosed = false; break; } MultiplyOperation multiply = new MultiplyOperation(); multiply.LeftOperand = storedOperation; current = multiply; mode = Mode.Replace; break; case Operator.Divide: if (parenClosed) { DivideOperation parenDivide = new DivideOperation(); parenDivide.LeftOperand = parenStack[0]; current = parenDivide; mode = Mode.Replace; parenClosed = false; break; } DivideOperation divide = new DivideOperation(); divide.LeftOperand = storedOperation; current = divide; mode = Mode.Replace; break; } }
private void HandleOperatorPressed(object sender, OperatorPressedEventArgs e) { HasSomethingBeenPressed = true; entry = Entry.Integer; decimalCount = 1; switch (e.Operator) { case Operator.Add: //convert to switches.... if (parenFlag) //if inside parentheses, do paren math { UpdateCurrentOperands(new AddOperation(), current, null); } else if (equalFlag) //do math correctly in weird situations ( ...x = + 3 should give x+3) { UpdateCurrentOperands(new AddOperation(), current.Result, null); equalFlag = false; } else if (current.LeftOperand != null && current.RightOperand == null) { UpdateCurrentOperands(current, current.LeftOperand, storedOperation); UpdateCurrentOperands(new AddOperation(), current.Result, null); } else if (current.LeftOperand == null && current.RightOperand == null) //first entry (or entry after clear) { UpdateCurrentOperands(new AddOperation(), storedOperation, null); } break; case Operator.Subtract: if (parenFlag) { UpdateCurrentOperands(new SubtractOperation(), current, null); } else if (equalFlag) { UpdateCurrentOperands(new SubtractOperation(), current.Result, null); equalFlag = false; } else if (current.LeftOperand != null && current.RightOperand == null) { UpdateCurrentOperands(current, current.LeftOperand, storedOperation); UpdateCurrentOperands(new SubtractOperation(), current.Result, null); } else if (current.LeftOperand == null && current.RightOperand == null) { UpdateCurrentOperands(new SubtractOperation(), storedOperation, null); } break; case Operator.Multiply: if (parenFlag) { UpdateCurrentOperands(new MultiplyOperation(), current, null); } else if (equalFlag) { UpdateCurrentOperands(new MultiplyOperation(), current.Result, null); equalFlag = false; } else if (current.LeftOperand != null && current.RightOperand == null) { UpdateCurrentOperands(current, current.LeftOperand, storedOperation); UpdateCurrentOperands(new MultiplyOperation(), current.Result, null); } else if (current.LeftOperand == null && current.RightOperand == null) { UpdateCurrentOperands(new MultiplyOperation(), storedOperation, null); } break; case Operator.Divide: if (parenFlag) { UpdateCurrentOperands(new DivideOperation(), current, null); } else if (equalFlag) { UpdateCurrentOperands(new DivideOperation(), current.Result, null); equalFlag = false; } else if (current.LeftOperand != null && current.RightOperand == null) { UpdateCurrentOperands(current, current.LeftOperand, storedOperation); UpdateCurrentOperands(new DivideOperation(), current.Result, null); } else if (current.LeftOperand == null && current.RightOperand == null) { UpdateCurrentOperands(new DivideOperation(), storedOperation, null); } break; } }