Ejemplo n.º 1
0
        public void Visit(Element element)
        {
            NumberElement numberElement = element as NumberElement;

            //check if eligible for "fizz" display
            if (((numberElement.Num % 3) == 0 || numberElement.Num.ToString().Contains("3")))
            {
                numberElement.FizzMsg = "fizz";
            }
        }
Ejemplo n.º 2
0
        public void Visit(Element element)
        {
            NumberElement numberElement = element as NumberElement;

            //check if eligible for "buzz" display
            if ((numberElement.Num % 5) == 0 || (numberElement.Num.ToString().Contains("5")))
            {
                numberElement.BuzzMsg = "buzz";
            }
        }
Ejemplo n.º 3
0
        public static string FizzBuzz(int number)
        {
            NumberElement e = new NumberElement(number);

            e.Accept(new FizzVisitor());
            e.Accept(new BuzzVisitor());
            e.Accept(new DeluxeVisitor());
            e.Accept(new DefaultVisitor());

            return(e.Msg);
        }
Ejemplo n.º 4
0
        public void Visit(Element element)
        {
            NumberElement numberElement = element as NumberElement;

            if (((numberElement.Num % 3) == 0 && (numberElement.Num.ToString().Contains("3"))) ||
                ((numberElement.Num % 5) == 0 && (numberElement.Num.ToString().Contains("5")))
                )
            {
                if (numberElement.Num % 2 == 0)
                {
                    numberElement.DeluxeMsg = "deluxe";
                }
                else
                {
                    numberElement.DeluxeMsg = "fake deluxe";
                }
            }
        }
Ejemplo n.º 5
0
        public void Visit(Element element)
        {
            NumberElement numberElement = element as NumberElement;

            if (numberElement.FizzMsg == null && numberElement.BuzzMsg == null && numberElement.DeluxeMsg == null)
            {
                numberElement.Msg = numberElement.Num.ToString();
            }
            else if (numberElement.BuzzMsg == null)
            {
                numberElement.Msg = numberElement.FizzMsg + " " + numberElement.DeluxeMsg;
            }
            else
            {
                numberElement.Msg = numberElement.FizzMsg + " "
                                    + numberElement.BuzzMsg + " "
                                    + numberElement.DeluxeMsg;
            }

            numberElement.Msg = numberElement.Msg.Trim();
        }