Example #1
0
        public static String Conversion(int number)
        {
            Expression[] expressions = new Expression[]
            {
                new RomanThousandExpression(),
                new RomanHundredExpression(),
                new RomanTenExpression(),
                new RomanOneExpression()
            };

            if (IsValidNumber(number))
            {
                var context = new RomanContext(number);

                foreach (var expression in expressions)
                {
                    expression.Interpret(context);
                }
                return("Decimal equivalent of " + number + " is " + context.Output);
            }
            else
            {
                return("The Number provided is not in a required range.");
            }
        }
Example #2
0
        public override void Interpret(RomanContext value)
        {
            while ((value.Input - 1000) >= 0)
            {
                value.Output += "M";

                value.Input -= 1000;
            }
        }
Example #3
0
        public override void Interpret(RomanContext value)
        {
            while ((value.Input - 9) >= 0)
            {
                value.Output += "IX";

                value.Input -= 9;
            }

            while ((value.Input - 5) >= 0)
            {
                value.Output += "V";

                value.Input -= 5;
            }

            while ((value.Input - 4) >= 0)
            {
                value.Output += "IV";

                value.Input -= 4;
            }

            while ((value.Input - 3) >= 0)
            {
                value.Output += "III";

                value.Input -= 3;
            }

            while ((value.Input - 2) >= 0)
            {
                value.Output += "II";

                value.Input -= 2;
            }

            while ((value.Input - 1) >= 0)
            {
                value.Output += "I";

                value.Input -= 1;
            }
        }
Example #4
0
        public override void Interpret(RomanContext value)
        {
            while ((value.Input - 900) >= 0)
            {
                value.Output += "CM";

                value.Input -= 900;
            }

            while ((value.Input - 500) >= 0)
            {
                value.Output += "D";

                value.Input -= 500;
            }

            while ((value.Input - 400) >= 0)
            {
                value.Output += "CD";

                value.Input -= 400;
            }

            while ((value.Input - 300) >= 0)
            {
                value.Output += "CCC";

                value.Input -= 300;
            }

            while ((value.Input - 200) >= 0)
            {
                value.Output += "CC";

                value.Input -= 200;
            }

            while ((value.Input - 100) >= 0)
            {
                value.Output += "C";

                value.Input -= 100;
            }
        }
Example #5
0
        public override void Interpret(RomanContext value)
        {
            while ((value.Input - 90) >= 0)
            {
                value.Output += "XC";

                value.Input -= 90;
            }

            while ((value.Input - 50) >= 0)
            {
                value.Output += "L";

                value.Input -= 50;
            }

            while ((value.Input - 40) >= 0)
            {
                value.Output += "XL";

                value.Input -= 40;
            }

            while ((value.Input - 30) >= 0)
            {
                value.Output += "XXX";

                value.Input -= 30;
            }

            while ((value.Input - 20) >= 0)
            {
                value.Output += "XX";

                value.Input -= 20;
            }

            while ((value.Input - 10) >= 0)
            {
                value.Output += "X";

                value.Input -= 10;
            }
        }
Example #6
0
 public abstract void Interpret(RomanContext value);