static void Main(string[] args) { var mikeCalc = new OneCalculatorToRuleThemAll <MikesNumbers>(); mikeCalc.Add(new MikesNumbers("Blah"), new MikesNumbers("Foo")); Console.ReadLine(); IntCalculator c = new IntCalculator(); c.Add(5, 8); c.Multiply(5, 8); c.Subtract(5, 8); c.Mod(5, 8); FloatCalculator c2 = new FloatCalculator(); float result = c2.Add(5.6f, 4.3f); c2.Subtract(5.6f, 4.3f); CustomNumberCalculator c3 = new CustomNumberCalculator(); var num1 = new CustomNumber("Daniel"); var num2 = new CustomNumber("Mike"); CustomNumber num3 = c3.Add(num1, num2); c3.Multiply(num1, num2); c3.Subtract(num1, num2); c3.Mod(num1, num2); Console.ReadLine(); }
public static void TestIntCalculator() { Console.Clear(); ICalculator <int> calc = new IntCalculator(); INumberValidator <int> validator = new IntValidator(); int value1, value2, result; while (true) { try { Console.Write("Введите операцию (+ - * /): "); ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.Escape) { return; } char operation = key.KeyChar; if (operations.IndexOf(operation) == -1) { Console.WriteLine("\r\nА вот и не правильно"); continue; } Console.Write("\r\nВведите 2 целых числа разделенных пробелом: "); if (!validator.ValidateTwoNumbers(Console.ReadLine(), out value1, out value2)) { Console.WriteLine("Неверный ввод. Придется повторить"); continue; } switch (operation) { case '+': result = calc.Add(value1, value2); break; case '-': result = calc.Add(value1, value2); break; case '*': result = calc.Multiply(value1, value2); break; case '/': result = calc.Divide(value1, value2); break; default: continue; } Console.WriteLine($"{ value1}{ operation}{ value2}={ result}"); } catch (Exception e) { Console.WriteLine($"Exception {e.GetType().Name}: {e.Message}"); } } }