コード例 #1
0
        public static void Main(string[] args)
        {
            var fizzBuzzService = new FizzBuzzCalculator();

            for (int i = 1; i <= 1000; i++)
            {
                var replacementText = fizzBuzzService.GetValue(i);
                Console.WriteLine(replacementText);
            }

            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //setup app
            IFizzBuzzCalculator calculator = new FizzBuzzCalculator();
            IOutput             output     = new Outputter(Console.Out);
            var app = new FizzBuzzProcessor(calculator, output);

            //process collection
            app.ProcessCollection(Enumerable.Range(MinValue, MaxValue));

            //hold screen
            Console.ReadLine();
        }
コード例 #3
0
        public List <string> CalculateResultsForNIterations(int numberOfIterations)
        {
            CheckIterationIsInRange(numberOfIterations);

            var resultList = new List <string>(numberOfIterations);
            var calculator = new FizzBuzzCalculator();

            for (int iterator = 1; iterator <= numberOfIterations; iterator++)
            {
                resultList.Add(calculator.CalculateCurrentValue(iterator));
            }

            return(resultList);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: gerardo007/FizzBuzz
        static void Main(string[] args)
        {
            int _lowerNumber, _higherNumber;

            var mappings = new Dictionary<Tuple<bool, bool>, string>
                {
                    { new Tuple<bool, bool>(true, true), "- FizzBuzz"},
                    { new Tuple<bool, bool>(true, false), "- Fizz"},
                    { new Tuple<bool, bool>(false, true), "- Buzz"},
                    { new Tuple<bool, bool>(false, false), " - N/A"}
                };

            try
            {

                Console.WriteLine("Enter a lower number: ");
                string LowerNumber = Console.ReadLine();

                if (int.TryParse(LowerNumber, out _lowerNumber))
                {
                    //Console.WriteLine("Thank you for entering: {0}", _lowerNumber):
                }
                else
                {
                    Console.WriteLine("Invalid input: {0}", LowerNumber);
                }
                Console.WriteLine("Enter a higher number: ");
                string HigherNumber = Console.ReadLine();
                if (int.TryParse(HigherNumber, out _higherNumber))
                {
                    //Console.WriteLine("Thank you for entering: {0}", _higherNumber);
                }
                else
                {
                    Console.WriteLine("Invalid input: {0}", HigherNumber);
                }

                if (_lowerNumber > _higherNumber)
                {
                    Console.WriteLine("Invalid Data. Higher number should be > than lower number");
                }
                else
                {
                    var fizzBuzz = new FizzBuzzCalculator(mappings, (n) => n % _lowerNumber == 0, (n) => n % _higherNumber == 0);

                    for (int i = 0; i < 200; i++)
                    {
                        Console.WriteLine(fizzBuzz.NumberFormat(i));
                    }

                    Console.ReadLine();
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }