예제 #1
0
        public static void Main(string[] args)
        {
            try
            {
                FractionExpressionEvaluator evaluator = new FractionExpressionEvaluator(
                    SettingsLoader.getWholeSeparator(),
                    SettingsLoader.getFractionSeparator(),
                    SettingsLoader.getAdditionOperator(),
                    SettingsLoader.getSubractionOperator(),
                    SettingsLoader.getMultiplicationOperator(),
                    SettingsLoader.getDivisionOperator(),
                    SettingsLoader.getNegativeCharacter(),
                    new FractionCalculator.Lib.FractionCalculator()
                    );

                //
                // Allow CLI argument-based operation, or interactive console.
                //
                if (args != null && args.Length > 0)
                {
                    try
                    {
                        Console.WriteLine(evaluator.Eval(args));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception: " + ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        Console.WriteLine("Please enter an expression: ");
                        string exp = Console.ReadLine();

                        if (String.IsNullOrWhiteSpace(exp))
                        {
                            throw new FormatException("Input cannot be empty.");
                        }

                        string[] consoleArgs = exp.Split(" ");

                        Console.WriteLine(evaluator.Eval(consoleArgs));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception: " + ex.Message);
                    }

                    Main(null);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Error: " + ex.Message);
            }
        }
예제 #2
0
        public string calc(string input)
        {
            string[] consoleArgs = input.Split(" ");

            return(evaluator.Eval(consoleArgs));
        }