/* * Constructor. */ public TestQuestionPage(Window contentWindow, TestSet testSet) { InitializeComponent(); this.contentWindow = contentWindow; this.testSet = testSet; this.currentTestQuestion = null; this.testSet.currentRoundQuestionIndex = 0; updatePage(); }
/* * Parses and returns a question. */ private static TestQuestion parseQuestion(String line) { TestQuestion question = new TestQuestion(); // If the first line is question text if (isText(line)) { // Current character index int characterIndex = 0; // Secondary character index (beginning of answer options) int secondaryCharacterIndex = line.Length; for (int i = 0; i < line.Length; i++) { if (isAnAnswerOption(line.Substring(i).Trim())) { secondaryCharacterIndex = i; break; } } // Parse the question text question.text = parseText(line.Substring(characterIndex, secondaryCharacterIndex - characterIndex).Trim()); // Parse the answer options if (isAnAnswerOption(line.Substring(secondaryCharacterIndex).Trim())) { question.answerOptions = parseAnswerOptions(line.Substring(secondaryCharacterIndex).Trim()); } else { Console.WriteLine("Problem: Invalid input to parseQuestion()."); } } else { Console.WriteLine("Problem: Invalid input to parseQuestion()."); } return(question); }
/* * Updates the page. */ private void updatePage() { // If there are more questions to present if (testSet.currentRoundQuestionIndex < testSet.numQuestionsPerRound) { // If there is no current question reference or the reference needs to be updated, update the page if (currentTestQuestion == null || currentTestQuestion != testSet.getCurrentQuestion()) { // Update the current question reference currentTestQuestion = testSet.getCurrentQuestion(); // Test label testLabel.Content = testSet.testSetInfo.testSetStringLong; // Round number roundNumberLabel.Content = "Round " + (testSet.currentRoundIndex + 1) + " / " + testSet.numRounds; // Question number questionNumberLabel.Content = "Question " + (testSet.currentRoundQuestionIndex + 1) + " / " + testSet.numQuestionsPerRound; // Question text block questionTextBlock.Text = currentTestQuestion.text; // Answer option A if (currentTestQuestion.answerOptions.ContainsKey('a')) { optionARadioButton.IsEnabled = true; optionARadioButton.Content = "a) " + currentTestQuestion.answerOptions['a']; } else { optionARadioButton.IsEnabled = false; optionARadioButton.Content = ""; } // Answer option B if (currentTestQuestion.answerOptions.ContainsKey('b')) { optionBRadioButton.IsEnabled = true; optionBRadioButton.Content = "b) " + currentTestQuestion.answerOptions['b']; } else { optionBRadioButton.IsEnabled = false; optionBRadioButton.Content = ""; } // Answer option C if (currentTestQuestion.answerOptions.ContainsKey('c')) { optionCRadioButton.IsEnabled = true; optionCRadioButton.Content = "c) " + currentTestQuestion.answerOptions['c']; } else { optionCRadioButton.IsEnabled = false; optionCRadioButton.Content = ""; } // Answer option D if (currentTestQuestion.answerOptions.ContainsKey('d')) { optionDRadioButton.IsEnabled = true; optionDRadioButton.Content = "d) " + currentTestQuestion.answerOptions['d']; } else { optionDRadioButton.IsEnabled = false; optionDRadioButton.Content = ""; } // Deselect the answer options optionARadioButton.IsChecked = false; optionBRadioButton.IsChecked = false; optionCRadioButton.IsChecked = false; optionDRadioButton.IsChecked = false; // If an answer option was previously selected, select the radio button if (currentTestQuestion.userAnswer == 'a') { optionARadioButton.IsChecked = true; } else if (currentTestQuestion.userAnswer == 'b') { optionBRadioButton.IsChecked = true; } else if (currentTestQuestion.userAnswer == 'c') { optionCRadioButton.IsChecked = true; } else if (currentTestQuestion.userAnswer == 'd') { optionDRadioButton.IsChecked = true; } // Warning label warningLabel.Visibility = Visibility.Hidden; // Back button updateBackButton(); // Next button updateNextButton(); } } else { // Go to the test score page contentWindow.Content = new TestScorePage(contentWindow, testSet); } }