// This method is used for adding and calculating the Pi and E number private void AddPiE(string value) { // Check if there is operator or not and then adding value to number 1 or 2 int index = @operator == null ? 0 : 1; // Jump into the CheckerActivity class to check the input if (CheckerActivity.IsInputValid(numbers, index, value)) { numbers[index] = value; Calculate(); } UpdateCalculatorText(); }
// This method is used for adding numbers or decimal point to the text view private void AddDigitOrDecimalPoint(string value) { // Check if there is operator or not and then adding value to number 1 or 2 int index = @operator == null ? 0 : 1; // Jump into the CheckerActivity class to check the input if (CheckerActivity.IsInputValid(numbers, index, value)) { // Check if user press equal or not // If user pressed equal and entered new number, // it will automaticall replace the old number to the new one if (this._justPressEqual) { numbers[index] = value; } else { numbers[index] += value; } } UpdateCalculatorText(); }
// This method will calculate all operations private void Calculate(string newOperatorFunction = null) { double?result = null; double?first = CheckerActivity.ParseValue(numbers[0]); double?second = CheckerActivity.ParseValue(numbers[1]); // Check if the text view already contained operation // It will calculate first and then jump into the condition for function if (first != null && @operator != null && second != null) { switch (@operator) { case "÷": result = first / second; break; case "×": result = first * second; break; case "+": result = first + second; break; case "-": result = first - second; break; } } if (result != null) { switch (@function) { case "Sin": result = Math.Sin((double)result); break; case "Cos": result = Math.Cos((double)result); break; case "Tan": result = Math.Tan((double)result); break; case "Log": result = Math.Log10((double)result); break; case "In": result = Math.Log((double)result); break; case "%": result = (double)result / ConstantContainer.percent; break; case "!": result = CheckerActivity.CalculateRecursion(result); break; } } else { switch (@function) { case "Sin": result = Math.Sin((double)first); break; case "Cos": result = Math.Cos((double)first); break; case "Tan": result = Math.Tan((double)first); break; case "Log": result = Math.Log10((double)first); break; case "In": result = Math.Log((double)first); break; case "%": result = (double)first / ConstantContainer.percent; break; case "!": result = CheckerActivity.CalculateRecursion(first); break; } } // Check if the result null or not and then check if the firt number is valid or not and get the second instead if (result == null) { result = first ?? second; } if (result != null) { double?finalResult = Math.Round((double)result, 8); numbers[0] = finalResult.ToString(); @operator = newOperatorFunction; @function = newOperatorFunction; numbers[1] = null; UpdateCalculatorText(); } }