Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.ArgumentOutOfRangeException">Something is wrong with the digits you specified.</exception>
        public Problem Generate()
        {
            Problem problem = new Problem();

            problem.Left = generateValue(LeftDigits, RightDigits);
            if (!Problem.IsUnary(Operation))
            {
                problem.Right = generateValue(RightDigits, LeftDigits);
            }
            problem.Operation = Operation;
            if (!Problem.IsUnary(Operation))
            {
                applyConstraints(ref problem);
            }

            switch (Operation)
            {
            case MathPractice.Operation.Addition:
                if (problem.Left.ToString().Length < problem.Right.ToString().Length)
                {
                    reverseOperands(ref problem);
                }
                break;

            case MathPractice.Operation.Subtraction:
                if (problem.Left < problem.Right)
                {
                    reverseOperands(ref problem);
                }
                break;

            case MathPractice.Operation.Multiplication:
                if (problem.Left.ToString().Length < problem.Right.ToString().Length)
                {
                    reverseOperands(ref problem);
                }
                break;
            }

            return(problem);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="System.ArgumentOutOfRangeException">Bad digit specifications.</exception>
        public void PrintProblem()
        {
            currentProblem = Generator.Generate();

            string leftText  = currentProblem.Left.ToString();
            string rightText = currentProblem.Right.ToString();
            char   opText    = getOperationText(currentProblem.Operation);

            Console.WriteLine("[#" + (TotalAnswers + 1).ToString() + "]");
            if (Generator.Operation == Operation.DayOfWeek) //todo: make this suck less
            {
                Console.Write("What is the day of the week for New Year's Day in the year " + currentProblem.Left.ToString() + "?  ");
            }
            else if (Problem.IsUnary(currentProblem.Operation))
            {
                Console.Write(leftText + opText + " = ");
            }
            else if (Vertical)
            {
                string answerPadding = getVerticalAnswerPadding(currentProblem);

                Console.WriteLine("------------------");
                Console.WriteLine("  " + answerPadding + leftText + "\t");
                Console.Write(opText + " ");
                for (int i = rightText.Length; i < leftText.Length; i++)
                {
                    Console.Write(" ");
                }
                Console.WriteLine(answerPadding + rightText + "\t");
                Console.WriteLine("------------------");
                Console.Write("  ");
            }
            else
            {
                Console.Write(leftText + " " + opText + " " + rightText + " = ");
            }
        }