Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            ISequence sequence = new FibonacciSequence();
            var       ui       = new FibonacciSequenceUI();
            var       app      = new FibonacciSequenceApp(ui, sequence);

            try
            {
                app.Run(args[0], args[1]);
            }
            catch (IndexOutOfRangeException exception)
            {
                ui.DisplayResult(FibonacciSequenceUI.Instruction);
                log.Error(exception);
            }
            catch (ArgumentException exception)
            {
                ui.DisplayResult(FibonacciSequenceUI.Mistake);
                ui.DisplayResult(FibonacciSequenceUI.Instruction);
                log.Error(exception);
            }
            catch (FormatException exception)
            {
                ui.DisplayResult(FibonacciSequenceUI.Mistake);
                ui.DisplayResult(FibonacciSequenceUI.Instruction);
                log.Error(exception);
            }
        }
Exemplo n.º 2
0
        private void GetSequence(int start, int end)
        {
            CheckRange(start, end);
            var index         = 0;
            var currentNumber = sequence[index];
            var isValid       = true;
            var isEmpty       = true;

            while (isValid)
            {
                if (currentNumber > start && currentNumber < end)
                {
                    ui.DisplayNumberOfSequence(currentNumber);
                    isEmpty = false;

                    ui.DisplayDelimiter(sequence[index + 1] < end
                        ? FibonacciSequenceUI.Comma
                        : FibonacciSequenceUI.Point);
                }

                if (currentNumber > end)
                {
                    isValid = false;
                }

                index++;
                currentNumber = sequence[index];
            }

            if (isEmpty)
            {
                ui.DisplayResult(FibonacciSequenceUI.EmptySequence);
            }
        }