/** * Result text containing whole calculation with result according to given state. */ private string GetResultText(CalculationState state, bool usingCurrentState = false) { var first = state.FirstNumber; var second = state.SecondNumber; var operationType = state.OperationType; if (first == null || second == null || operationType == null) { if (usingCurrentState) { RestoreCalculationState(); } return("0"); } var operation = GetOperationText(state); var result = GetResult((double)first, (double)second, (OperationTypes)operationType); var resultOperationText = state.FirstNumber + " " + operation + " " + state.SecondNumber + " = " + result; if (usingCurrentState) { SaveAndRestoreCalculationState(); } return(resultOperationText); }
private string GetOperationText(CalculationState state) { switch (state.OperationType) { case OperationTypes.ADD: return("+"); case OperationTypes.SUBTRACT: return("-"); case OperationTypes.MULTIPLY: return("*"); case OperationTypes.DIVIDE: return("/"); default: return(null); } }
private void RestoreCalculationState() { state = new CalculationState(); }
public CalculatorManager() { state = new CalculationState(); calculationsList = new List <CalculationState>(); }