-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
public abstract class Question
{
public string QuestionText { get; set; }
public abstract bool CheckAnswer(string answer);
public abstract string GetCorrectAnswer();
// Hàm hiển thị giao diện
public abstract void RenderToUI(Label lbl, RadioButton[] options, TextBox txt);
}
// MULTIPLE CHOICE
public class MultipleChoiceQuestion : Question
{
public string[] Options { get; set; }
public int CorrectOption { get; set; }
public override bool CheckAnswer(string answer)
{
return Options[CorrectOption].Trim().Equals(answer.Trim(), StringComparison.OrdinalIgnoreCase);
}
public override string GetCorrectAnswer()
{
return (CorrectOption >= 0 && CorrectOption < Options.Length)
? Options[CorrectOption]
: "(Invalid correct option)";
}
public override void RenderToUI(Label lbl, RadioButton[] options, TextBox txt)
{
lbl.Text = QuestionText;
for (int i = 0; i < options.Length; i++)
{
if (i < Options.Length)
{
options[i].Visible = true;
options[i].Text = Options[i];
options[i].Checked = false;
}
else
{
options[i].Visible = false;
}
}
txt.Visible = false;
}
}
// OPEN ENDED
public class OpenEndedQuestion : Question
{
public List AcceptedAnswers { get; set; }
public override bool CheckAnswer(string answer)
{
return AcceptedAnswers.Any(a => a.Equals(answer, StringComparison.OrdinalIgnoreCase));
}
public override string GetCorrectAnswer()
{
return string.Join(", ", AcceptedAnswers);
}
public override void RenderToUI(Label lbl, RadioButton[] options, TextBox txt)
{
lbl.Text = QuestionText;
foreach (var opt in options) opt.Visible = false;
txt.Visible = true;
txt.Text = "";
}
}
// TRUE / FALSE
public class TrueFalseQuestion : Question
{
public bool IsTrue { get; set; }
public override bool CheckAnswer(string answer)
{
return (IsTrue && answer.Equals("True", StringComparison.OrdinalIgnoreCase)) ||
(!IsTrue && answer.Equals("False", StringComparison.OrdinalIgnoreCase));
}
public override string GetCorrectAnswer()
{
return IsTrue ? "True" : "False";
}
public override void RenderToUI(Label lbl, RadioButton[] options, TextBox txt)
{
lbl.Text = QuestionText;
options[0].Visible = true; options[0].Text = "True"; options[0].Checked = false;
options[1].Visible = true; options[1].Text = "False"; options[1].Checked = false;
options[2].Visible = false; options[3].Visible = false;
txt.Visible = false;
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels