Exemple #1
0
        static void Main(string[] args)
        {
            Quiz   myQuiz = new Quiz();
            string userInput;

            MultipleChoice myQuestion = new MultipleChoice("MC 1", new Dictionary <string, string> {
                { "a", "wrong" }, { "b", "correct" }, { "c", "wrong" }, { "d", "wrong" }
            }, "b");
            MultipleChoice myQuestion2 = new MultipleChoice("MC 2", new Dictionary <string, string> {
                { "a", "wrong" }, { "b", "wrong" }, { "c", "correct" }, { "d", "wrong" }
            }, "c");
            TrueFalse myQuestion3 = new TrueFalse("TF 1", new Dictionary <string, string> {
                { "a", "true" }, { "b", "false" }
            }, "a");
            Checkbox myQuestion4 = new Checkbox("CB 1", new Dictionary <string, string> {
                { "a", "correct" }, { "b", "correct" }, { "c", "wrong" }, { "d", "correct" }
            }, "abd");
            ShortAnswer myQuestion5 = new ShortAnswer("SA 1");


            myQuiz.AddQuestion(myQuestion);
            myQuiz.AddQuestion(myQuestion2);
            myQuiz.AddQuestion(myQuestion3);
            myQuiz.AddQuestion(myQuestion4);
            myQuiz.AddQuestion(myQuestion5);

            while (true)
            {
                Console.WriteLine("1 - Add questions\n2 - Run quiz\n3 - Grade the quiz");
                userInput = Console.ReadLine();
                if (Equals(userInput, "1"))
                {
                    myQuiz.AddQuestion();
                }
                else if (Equals(userInput, "2"))
                {
                    myQuiz.RunQuiz();
                }
                else if (Equals(userInput, "3"))
                {
                    Console.WriteLine($"\nYou answered {myQuiz.GradeQuiz():P1} correctly.\n");
                }
            }
        }
Exemple #2
0
        public void AddQuestion()
        {
            Question newQuestion = new Question();

            do
            {
                int    userSelection;
                string userInput;
                Console.Write("What type of question to add:\n 1 - Multiple Choice\n 2 - Checkbox\n 3 - True/False\n> ");
                while (!int.TryParse(Console.ReadLine(), out userSelection))
                {
                    Console.Write("Invalid entry, choose question type by number: ");
                }
                if (userSelection == 1)
                {
                    newQuestion = new MultipleChoice();
                }
                else if (userSelection == 2)
                {
                    newQuestion = new Checkbox();
                }
                else if (userSelection == 3)
                {
                    newQuestion = new TrueFalse();
                }

                do
                {
                    Console.WriteLine("Enter the question prompt: ");
                    userInput = Console.ReadLine();
                    Console.Write($"\tYou entered the question prompt:\n\t{userInput}\n\tIs that correct (y/n)?: ");
                } while (!Equals(Console.ReadLine().ToLower(), "y"));
                newQuestion.Prompt = userInput;

                if (!newQuestion.GetType().Equals(typeof(TrueFalse)))
                {
                    do
                    {
                        Console.WriteLine("Enter the possible answers:\n(Hit \"Enter\" when done)");
                        userInput = Console.ReadLine();
                        char choice = 'a';
                        while (!Equals(userInput.ToLower(), ""))
                        {
                            newQuestion.possibleAnswers[choice.ToString()] = userInput;
                            choice++;
                            userInput = Console.ReadLine();
                        }
                        Console.WriteLine("\tYou entered the possible answers: ");
                        foreach (KeyValuePair <string, string> a in newQuestion.possibleAnswers)
                        {
                            Console.WriteLine($"\t{a.Key} - {a.Value}");
                        }
                        Console.Write("\tIs that correct(y / n) ? ");
                    } while (!Equals(Console.ReadLine().ToLower(), "y"));
                }
                else
                {
                    Console.WriteLine("\tPossible answers: ");
                    newQuestion.possibleAnswers["a"] = "true";
                    newQuestion.possibleAnswers["b"] = "false";
                    foreach (KeyValuePair <string, string> a in newQuestion.possibleAnswers)
                    {
                        Console.WriteLine($"\t{a.Key} - {a.Value}");
                    }
                }

                do
                {
                    Console.WriteLine("Enter the letters that correspond to the correct choice(s)");
                    userInput = Console.ReadLine();
                    char[] userArr = userInput.ToCharArray();
                    Array.Sort(userArr);
                    newQuestion.CorrectAnswer = new string(userArr);
                    Console.WriteLine("\tYou entered the correct answer(s) as: {0}", newQuestion.CorrectAnswer);
                    Console.Write("\tIs that correct(y / n) ? ");
                } while (!Equals(Console.ReadLine().ToLower(), "y"));
                Console.Clear();
                Console.Write($"Your {newQuestion.GetType()} question will appear as follows:\n\n{newQuestion.Display()}\nWith correct answer(s) marked as: {newQuestion.CorrectAnswer}\n\nIs that correct (y to accept, n to start over): ");
            } while (!Equals(Console.ReadLine().ToLower(), "y"));
            questions.Add(newQuestion);
        }