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;
|
||||
|
||||
public class MultipleChoiceQuestions
|
||||
public class MultipleChoiceQuestions: IQuestion
|
||||
{
|
||||
private readonly string _question;
|
||||
private readonly string[] _answers;
|
||||
|
@ -23,5 +23,9 @@ public class MultipleChoiceQuestions
|
|||
var answer = _answers[i];
|
||||
Console.WriteLine(answerNo + ": " + answer);
|
||||
}
|
||||
Console.WriteLine("Velg Svaralternativ: ");
|
||||
var selectedAnswerNoStr = Console.ReadLine();
|
||||
var selectedAnswerNo = Convert.ToInt32(selectedAnswerNoStr);
|
||||
return selectedAnswerNo == _correctAnswerNo;
|
||||
}
|
||||
}
|
|
@ -1,15 +1,16 @@
|
|||
using IntroInterface;
|
||||
|
||||
var questions = new ???[]
|
||||
var questions = new IQuestion[]
|
||||
{
|
||||
new SimpleAnswerQuestion("Hva er 2+2?", "4"),
|
||||
new MultipleChoiceQuestions("Hva er hovedstaden i Norge?", 3,"Stavern", "Larvik","Oslo"),
|
||||
new SingleAnswerQuestion("Hva er 2+2?", "4"),
|
||||
new MultipleChoiceQuestions("Hva er hovedstaden i Norge?", 3,"Stavern", "Larvik","Oslo"),
|
||||
};
|
||||
|
||||
var points = 0;
|
||||
foreach (var question in questions)
|
||||
{
|
||||
var isCorrect = question.Run();
|
||||
|
||||
if (isCorrect)
|
||||
{
|
||||
Console.WriteLine("Riktig!");
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
namespace IntroInterface;
|
||||
|
||||
public class SimpleAnswerQuestion
|
||||
public class SingleAnswerQuestion: IQuestion
|
||||
{
|
||||
private readonly string _question;
|
||||
private readonly string _correctanswer;
|
||||
|
||||
public SimpleAnswerQuestion(string question, string correctanswer)
|
||||
public SingleAnswerQuestion(string question, string correctanswer)
|
||||
{
|
||||
_correctanswer = correctanswer;
|
||||
_question = question;
|
Loading…
Reference in a new issue