public void Restore(string n1, string n2, char?op) { result.Set(n1); operand.Set(n2); previousOperator = op; currentOperandDisplayed = result; }
public Calculator() { resultState = new ResultState(); operandState = new OperandState(); operatorValue = null; currentState = resultState; stableState = operandState; }
public Calculator() { // Display 0 initially Console.WriteLine("0"); result = new OperandState(); operand = new OperandState(); currentOperandDisplayed = result; }
public void SwitchNumbersBeingDisplayed() { if (currentOperandDisplayed == result) { currentOperandDisplayed = operand; } else { currentOperandDisplayed = result; } }
public string GetResultOrError(float num1, float num2, char?currentOperator) { var result = OperandState.GetResult(num1, num2, (char)previousOperator); if (result == "error") { Restore("", "", null); return(OperandState.Error); } Restore(result, "", currentOperator); // If current operator is not '=', set to modify number 2 if (currentOperator != null) { SwitchNumbersBeingDisplayed(); } return(this.result.content); }