Exemple #1
0
        /// <summary>
        /// Runs application
        /// </summary>
        internal void Run()
        {
            _userInteraction.DisplayInfo("This application displays pairs from an imput list. Sum of these pairs equal specific value X");
            _userInteraction.DisplayInfo(string.Empty);

            _userInteraction.DisplayInfo("Enter an input list of numbers (Int32) separated by space ' ':");
            _userInteraction.DisplayInfo("Example: 1 3 5 6");
            var line = _userInteraction.ReadUserInput();

            if (string.IsNullOrEmpty(line))
            {
                _userInteraction.DisplayInfo("The line is empty.");
                return;
            }

            var stringList = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            IEnumerable <int> numberList;

            try
            {
                numberList = ConvertToIntArray(stringList);
            }
            catch (ArgumentException ex)
            {
                _userInteraction.DisplayInfo(ex.Message);
                return;
            }

            _userInteraction.DisplayInfo("Enter X - sum of pair:");
            line = _userInteraction.ReadUserInput();
            if (string.IsNullOrEmpty(line))
            {
                _userInteraction.DisplayInfo("The line is empty.");
                return;
            }

            int x;

            if (!int.TryParse(line, out x))
            {
                _userInteraction.DisplayInfo("The X is invalid.");
                return;
            }

            var pairs = NumberTool.MatchSumOfPairs(numberList, x);

            DisplayPairs(pairs);
        }