Nå med interface
This commit is contained in:
parent
9f4483e85f
commit
e71dc82f85
6
Emne 3/IntroInterface/IntroInterface/IQuestion.cs
Normal file
6
Emne 3/IntroInterface/IntroInterface/IQuestion.cs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
namespace IntroInterface;
|
||||||
|
|
||||||
|
public interface IQuestion
|
||||||
|
{
|
||||||
|
bool Run();
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
namespace IntroInterface;
|
namespace IntroInterface;
|
||||||
|
|
||||||
public class MultipleChoiceQuestions
|
public class MultipleChoiceQuestions: IQuestion
|
||||||
{
|
{
|
||||||
private readonly string _question;
|
private readonly string _question;
|
||||||
private readonly string[] _answers;
|
private readonly string[] _answers;
|
||||||
|
@ -23,5 +23,9 @@ public class MultipleChoiceQuestions
|
||||||
var answer = _answers[i];
|
var answer = _answers[i];
|
||||||
Console.WriteLine(answerNo + ": " + answer);
|
Console.WriteLine(answerNo + ": " + answer);
|
||||||
}
|
}
|
||||||
|
Console.WriteLine("Velg Svaralternativ: ");
|
||||||
|
var selectedAnswerNoStr = Console.ReadLine();
|
||||||
|
var selectedAnswerNo = Convert.ToInt32(selectedAnswerNoStr);
|
||||||
|
return selectedAnswerNo == _correctAnswerNo;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
using IntroInterface;
|
using IntroInterface;
|
||||||
|
|
||||||
var questions = new ???[]
|
var questions = new IQuestion[]
|
||||||
{
|
{
|
||||||
new SimpleAnswerQuestion("Hva er 2+2?", "4"),
|
new SingleAnswerQuestion("Hva er 2+2?", "4"),
|
||||||
new MultipleChoiceQuestions("Hva er hovedstaden i Norge?", 3,"Stavern", "Larvik","Oslo"),
|
new MultipleChoiceQuestions("Hva er hovedstaden i Norge?", 3,"Stavern", "Larvik","Oslo"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
foreach (var question in questions)
|
foreach (var question in questions)
|
||||||
{
|
{
|
||||||
var isCorrect = question.Run();
|
var isCorrect = question.Run();
|
||||||
|
|
||||||
if (isCorrect)
|
if (isCorrect)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Riktig!");
|
Console.WriteLine("Riktig!");
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
namespace IntroInterface;
|
namespace IntroInterface;
|
||||||
|
|
||||||
public class SimpleAnswerQuestion
|
public class SingleAnswerQuestion: IQuestion
|
||||||
{
|
{
|
||||||
private readonly string _question;
|
private readonly string _question;
|
||||||
private readonly string _correctanswer;
|
private readonly string _correctanswer;
|
||||||
|
|
||||||
public SimpleAnswerQuestion(string question, string correctanswer)
|
public SingleAnswerQuestion(string question, string correctanswer)
|
||||||
{
|
{
|
||||||
_correctanswer = correctanswer;
|
_correctanswer = correctanswer;
|
||||||
_question = question;
|
_question = question;
|
Loading…
Reference in a new issue