diff --git a/Emne 3/IntroInterface/IntroInterface/MultipleChoiceQuestions.cs b/Emne 3/IntroInterface/IntroInterface/MultipleChoiceQuestions.cs new file mode 100644 index 0000000..baa2fe9 --- /dev/null +++ b/Emne 3/IntroInterface/IntroInterface/MultipleChoiceQuestions.cs @@ -0,0 +1,27 @@ +namespace IntroInterface; + +public class MultipleChoiceQuestions +{ + private readonly string _question; + private readonly string[] _answers; + private readonly int _correctAnswerNo; + + public MultipleChoiceQuestions(string question, int correctAnswerNo, params string[] answers) + { + _question = question; + _correctAnswerNo = correctAnswerNo; + _answers = answers; + } + + public bool Run() + { + Console.WriteLine(_question); + Console.WriteLine("Svaralternativer: "); + for (var i = 0; i < _answers.Length; i++) + { + var answerNo = i + 1; + var answer = _answers[i]; + Console.WriteLine(answerNo + ": " + answer); + } + } +} \ No newline at end of file diff --git a/Emne 3/IntroInterface/IntroInterface/Program.cs b/Emne 3/IntroInterface/IntroInterface/Program.cs index e5dff12..adb3dc7 100644 --- a/Emne 3/IntroInterface/IntroInterface/Program.cs +++ b/Emne 3/IntroInterface/IntroInterface/Program.cs @@ -1,3 +1,24 @@ -// See https://aka.ms/new-console-template for more information +using IntroInterface; -Console.WriteLine("Hello, World!"); \ No newline at end of file + var questions = new ???[] + { + new SimpleAnswerQuestion("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!"); + points++; + } + else + { + Console.WriteLine("Feil! :-("); + } + } + + Console.WriteLine($"Du fikk {points} poeng."); \ No newline at end of file diff --git a/Emne 3/IntroInterface/IntroInterface/SimpleAnswerQuestion.cs b/Emne 3/IntroInterface/IntroInterface/SimpleAnswerQuestion.cs new file mode 100644 index 0000000..3985708 --- /dev/null +++ b/Emne 3/IntroInterface/IntroInterface/SimpleAnswerQuestion.cs @@ -0,0 +1,20 @@ +namespace IntroInterface; + +public class SimpleAnswerQuestion +{ + private readonly string _question; + private readonly string _correctanswer; + + public SimpleAnswerQuestion(string question, string correctanswer) + { + _correctanswer = correctanswer; + _question = question; + } + + public bool Run() + { + Console.Write(_question + " "); + var answer = Console.ReadLine(); + return answer == _correctanswer; + } +} \ No newline at end of file