diff --git a/README.md b/README.md index fde4ffa..e705bcf 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,44 @@ Bu uygulama, kullanıcıların çeşitli sınav kitapçıklarından soruları ç 3. Kitapçık seçildikten sonra, kullanıcı soruları çözebilir. 4. Soruları çözdükten sonra, kullanıcı cevap anahtarlarını görüntüleyebilir. +## Veri Örneği + +Örnek JSON veri: + +```json +[ + { + "Id": 1, + "AskText": "Android uygulama geliştirmede en yaygın kullanılan programlama dili nedir?", + "Explanation": null, + "Difficulty": "Medium", + "QuestionOptions": [ + { + "Id": 1, + "Text": "Java", + "IsCorrect": true + }, + { + "Id": 2, + "Text": "C#", + "IsCorrect": false + }, + { + "Id": 3, + "Text": "Python", + "IsCorrect": false + }, + { + "Id": 4, + "Text": "JavaScript", + "IsCorrect": false + } + ] + } +] + +``` + ## Özellikler - Kullanıcı dostu arayüz @@ -32,7 +70,7 @@ Bu uygulama, kullanıcıların çeşitli sınav kitapçıklarından soruları ç ## Kurulum -1. Bu depoyu klonlayın: `https://github.com/ilyasBozdemir/quiz-console-app` +1. Bu depoyu klonlayın: `git clone https://github.com/ilyasBozdemir/quiz-console-app` 2. Visual Studio'da çözümü açın: `quiz-console-app.sln` 3. Uygulamayı derleyin ve çalıştırın. @@ -40,8 +78,8 @@ Bu uygulama, kullanıcıların çeşitli sınav kitapçıklarından soruları ç 1. Bu depoyu çatallayın (fork). 2. Yeni bir dal (branch) oluşturun: `git checkout -b new-feature` -3. Değişikliklerinizi yapın ve bunları işleyin (commit): `git commit -am 'Yeni özellik ekle'` -4. Dalınızı ana depoya gönderin (push): `git push origin yeni-ozellik` +3. Değişikliklerinizi yapın ve bunları işleyin (commit): `git commit -m 'Yeni özellik ekle'` +4. Dalınızı ana depoya gönderin (push): `git push origin new-feature` 5. Bir birleştirme isteği (pull request) gönderin. ## Lisans diff --git a/quiz-console-app/Constants/OptionFormats.cs b/quiz-console-app/Constants/OptionFormats.cs deleted file mode 100644 index f666432..0000000 --- a/quiz-console-app/Constants/OptionFormats.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace quiz_console_app.Constants; - -public static class OptionFormats -{ - public const string Alphabetical = "A,B,C,D,E"; - public const string RomanNumerals = "I,II,III,IV,V"; -} diff --git a/quiz-console-app/Enums/DifficultyLevel.cs b/quiz-console-app/Enums/DifficultyLevel.cs index 2a1befc..8cc843b 100644 --- a/quiz-console-app/Enums/DifficultyLevel.cs +++ b/quiz-console-app/Enums/DifficultyLevel.cs @@ -1,8 +1,11 @@ namespace quiz_console_app.Enums; +[Flags] public enum DifficultyLevel { - Easy, - Medium, - Hard + Easy = 1, + Medium = 2, + Hard = 4 } + + diff --git a/quiz-console-app/Enums/OptionType.cs b/quiz-console-app/Enums/OptionType.cs deleted file mode 100644 index 073e5e5..0000000 --- a/quiz-console-app/Enums/OptionType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace quiz_console_app.Enums; - -public enum OptionType -{ - Alphabetical, // A, B, C, D, E - RomanNumerals, // I, II, III, IV, V - Custom -} diff --git a/quiz-console-app/Enums/QuizMode.cs b/quiz-console-app/Enums/QuizMode.cs new file mode 100644 index 0000000..ec3df64 --- /dev/null +++ b/quiz-console-app/Enums/QuizMode.cs @@ -0,0 +1,8 @@ +namespace quiz_console_app.Enums; +[Flags] +public enum QuizMode +{ + Quiz = 1, + DisplayBooklets = 2, + ExportData = 3 +} diff --git a/quiz-console-app/Helpers/ConsoleColors.cs b/quiz-console-app/Helpers/ConsoleColors.cs index 93e196d..8f4ae75 100644 --- a/quiz-console-app/Helpers/ConsoleColors.cs +++ b/quiz-console-app/Helpers/ConsoleColors.cs @@ -7,6 +7,6 @@ public static class ConsoleColors public static readonly ConsoleColor Title = ConsoleColor.DarkGreen; public static readonly ConsoleColor Info = ConsoleColor.DarkBlue; public static readonly ConsoleColor Warning = ConsoleColor.Yellow; - public static readonly ConsoleColor Debug = ConsoleColor.Magenta; - public static readonly ConsoleColor Prompt = ConsoleColor.Cyan; + public static readonly ConsoleColor Debug = ConsoleColor.Cyan; + public static readonly ConsoleColor Prompt = ConsoleColor.Magenta; } diff --git a/quiz-console-app/Helpers/QuizDisplay.cs b/quiz-console-app/Helpers/QuizDisplay.cs index d1ffe89..5e19f83 100644 --- a/quiz-console-app/Helpers/QuizDisplay.cs +++ b/quiz-console-app/Helpers/QuizDisplay.cs @@ -8,7 +8,6 @@ public static void DisplayBooklets(List booklets) { foreach (var booklet in booklets) { - Console.WriteLine(); ConsoleHelper.WriteColored("Kitapçık Id: ", ConsoleColors.Info); ConsoleHelper.WriteColoredLine(booklet.Id, ConsoleColors.Default); @@ -44,6 +43,9 @@ public static void DisplayAnswerKeys(List answerKeys) } ConsoleHelper.WriteColored("Cevap Anahtarları:", ConsoleColors.Info); + + int questionNumber = 1; + foreach (var answerKey in answerKeys) { ConsoleHelper.WriteColored("Kitapçık Id: ", ConsoleColors.Info); @@ -52,8 +54,12 @@ public static void DisplayAnswerKeys(List answerKeys) ConsoleHelper.WriteColored(" Soru Id: ", ConsoleColors.Info); ConsoleHelper.WriteColoredLine(answerKey.QuestionId, ConsoleColors.Default); - ConsoleHelper.WriteColored(" Doğru Seçenek Id: ", ConsoleColors.Info); - ConsoleHelper.WriteColoredLine(answerKey.CorrectOptionId, ConsoleColors.Default); + ConsoleHelper.WriteColored(" Doğru Seçenek : ", ConsoleColors.Info); + ConsoleHelper.WriteColored(answerKey.CorrectOptionText, ConsoleColors.Default); + + ConsoleHelper.WriteColoredLine(answerKey.CorrectOptionText, ConsoleColors.Default); + + questionNumber++; } } } \ No newline at end of file diff --git a/quiz-console-app/Models/Booklet.cs b/quiz-console-app/Models/Booklet.cs index 3d9968c..8f44045 100644 --- a/quiz-console-app/Models/Booklet.cs +++ b/quiz-console-app/Models/Booklet.cs @@ -7,7 +7,6 @@ public class Booklet public int Id { get; set; } public string BookletName { get; set; } public List Questions { get; set; } - public OptionType OptionType { get; set; } public Booklet() { diff --git a/quiz-console-app/Program.cs b/quiz-console-app/Program.cs index c326c76..9fd3147 100644 --- a/quiz-console-app/Program.cs +++ b/quiz-console-app/Program.cs @@ -1,15 +1,4 @@ -using quiz_console_app.Helpers; -using quiz_console_app.Models; -using quiz_console_app.Services; +using quiz_console_app.Services; -QuizService quizService = new QuizService(); - - -List questions = new QuestionLoader().LoadQuestionsFromJson("software_questions.json"); // default path : {root-project}/bin/Debug/net8.0/software_questions.json - -quizService.GenerateBooklets(questions, 1); - -QuizDisplay.DisplayBooklets(quizService.Booklets); -QuizDisplay.DisplayAnswerKeys(quizService.AnswerKeys); - -Console.ReadLine(); \ No newline at end of file +QuizModeHandlerService quizModeHandlerService = new QuizModeHandlerService(); +quizModeHandlerService.ShowMainMenu(); diff --git a/quiz-console-app/Screens/DisplayBookletScreen.cs b/quiz-console-app/Screens/DisplayBookletScreen.cs new file mode 100644 index 0000000..2e69f4d --- /dev/null +++ b/quiz-console-app/Screens/DisplayBookletScreen.cs @@ -0,0 +1,29 @@ +using quiz_console_app.Helpers; +using quiz_console_app.Models; +using quiz_console_app.Services; +using quiz_console_app.ViewModels; + +namespace quiz_console_app.Screens; + +public class DisplayBookletScreen +{ + private readonly QuizService _quizService; + private readonly QuestionLoader _questionLoader; + private readonly List _questions; + private readonly List _userAnswers; + private readonly List _answerKeys; + public DisplayBookletScreen() + { + _questionLoader = new QuestionLoader(); + _questions = _questionLoader.LoadQuestionsFromJson("software_questions.json"); + _quizService = new QuizService(); + _quizService.GenerateBooklets(_questions, 1); + _userAnswers = new List(); + _answerKeys = QuizService.AnswerKeys; + } + + public void Start() + { + + } +} diff --git a/quiz-console-app/Screens/ExportDataScreen.cs b/quiz-console-app/Screens/ExportDataScreen.cs new file mode 100644 index 0000000..3c921b1 --- /dev/null +++ b/quiz-console-app/Screens/ExportDataScreen.cs @@ -0,0 +1,9 @@ +namespace quiz_console_app.Screens; + +public class ExportDataScreen +{ + public void Start() + { + + } +} diff --git a/quiz-console-app/Screens/QuizModeScreen.cs b/quiz-console-app/Screens/QuizModeScreen.cs new file mode 100644 index 0000000..97d9f36 --- /dev/null +++ b/quiz-console-app/Screens/QuizModeScreen.cs @@ -0,0 +1,100 @@ +using quiz_console_app.Helpers; +using quiz_console_app.Models; +using quiz_console_app.Services; +using quiz_console_app.ViewModels; + +namespace quiz_console_app.Screens; + +public class QuizModeScreen +{ + private readonly QuizService _quizService; + private readonly QuestionLoader _questionLoader; + private readonly List _questions; + private readonly List _userAnswers; + private readonly List _answerKeys; + + public QuizModeScreen() + { + _questionLoader = new QuestionLoader(); + _questions = _questionLoader.LoadQuestionsFromJson("software_questions.json"); + _quizService = new QuizService(); + _quizService.GenerateBooklets(_questions, 1); + _userAnswers = new List(); + _answerKeys = QuizService.AnswerKeys; + } + + public void Start() + { + var Booklet = QuizService.Booklets.FirstOrDefault(); + int questionNumber = 1; + foreach (var question in Booklet.Questions) + { + ConsoleHelper.WriteColoredLine($"{questionNumber}. Soru: ", ConsoleColors.Info); + ConsoleHelper.WriteColoredLine(question.AskText, ConsoleColors.Default); + + for (int i = 0; i < question.QuestionOptions.Count; i++) + { + char optionLetter = (char)(65 + i); + + ConsoleHelper.WriteColored($"{optionLetter})", ConsoleColors.Info); + ConsoleHelper.WriteColored( + $"{question.QuestionOptions[i].Text} ", + ConsoleColors.Default + ); + } + Console.WriteLine(); + Console.Write("Cevabınızı girin (Boş bırakmak için Enter tuşuna basın) : "); + string userAnswerFromReadLine = Console.ReadLine().ToUpper(); + Console.WriteLine(); + if ( + userAnswerFromReadLine.Length == 1 + && userAnswerFromReadLine[0] >= (char)65 + && userAnswerFromReadLine[0] <= (char)(65 + question.QuestionOptions.Count - 1) + ) + { + _userAnswers.Add( + new UserAnswerKeyViewModel + { + BookletId = Booklet.Id, + QuestionId = question.Id, + UserAnswerOption = userAnswerFromReadLine + } + ); + questionNumber++; + } + else if (userAnswerFromReadLine.Length == 0) // cevap null ise + { + _userAnswers.Add( + new UserAnswerKeyViewModel + { + BookletId = Booklet.Id, + QuestionId = question.Id, + UserAnswerOption = null + } + ); + questionNumber++; + } + else + { + char optionLetter = (char)64; + string optionsText = ""; + for (int i = 0; i < question.QuestionOptions.Count; i++) + { + optionLetter++; + optionsText += + (i != 0) + ? (i != question.QuestionOptions.Count - 1) + ? $", {optionLetter}" + : $" veya {optionLetter}" + : $"{optionLetter}"; + } + + string errorMessage = + $"Geçersiz cevap. Lütfen {optionsText} harflerinden birini girin. veya boş bırakmak için sadece Enter tuşuna basın."; + + ConsoleHelper.WriteColoredLine(errorMessage, ConsoleColors.Error); + } + } + _quizService.EvaluateQuizResults(_userAnswers); + } +} diff --git a/quiz-console-app/Services/QuizModeHandlerService.cs b/quiz-console-app/Services/QuizModeHandlerService.cs new file mode 100644 index 0000000..5a6a32f --- /dev/null +++ b/quiz-console-app/Services/QuizModeHandlerService.cs @@ -0,0 +1,81 @@ +using quiz_console_app.Enums; +using quiz_console_app.Helpers; +using quiz_console_app.Screens; + +namespace quiz_console_app.Services; + +public class QuizModeHandlerService +{ + public void StartMode(QuizMode mode) + { + Console.Clear(); + switch (mode) + { + case QuizMode.Quiz: + new QuizModeScreen().Start(); + break; + case QuizMode.DisplayBooklets: + new DisplayBookletScreen().Start(); + break; + case QuizMode.ExportData: + new ExportDataScreen().Start(); + break; + default: + Console.WriteLine("Geçersiz mod."); + break; + } + } + + public void ShowMainMenu() + { + + string errorMessage = ""; + string[] options = + { + "Quiz Çözme Modu", + "Kitapçıkları ve Cevap Anahtarlarını Görüntüleme Modu", + "Verileri Dışa Aktarma Modu", + }; + + for (int i = 0; i < options.Length; i++) + errorMessage += (i != 0) + ? (i != options.Length - 1) + ? $", {i + 1}" + : $" veya {i + 1}" + : $"{i + 1}"; + + errorMessage = $"Geçersiz seçim. Lütfen {errorMessage} girin."; + + ConsoleHelper.WriteColoredLine("Seçiminizi yapın\n".ToUpper(), ConsoleColors.Title); + + for (int i = 0; i < options.Length; i++) + { + ConsoleHelper.WriteColored($"{i + 1}", ConsoleColors.Info); + Console.WriteLine($" => {options[i]}"); + } + bool menuState = true; + while (menuState) + { + Console.ForegroundColor = ConsoleColors.Prompt; + string userInput = Console.ReadLine(); + Console.ResetColor(); + int choice; + if (int.TryParse(userInput, out choice)) + if (Enum.IsDefined(typeof(QuizMode), choice)) + { + StartMode((QuizMode)choice); + break; + } + else + ConsoleHelper.WriteColoredLine(errorMessage, ConsoleColors.Error); + + else + ConsoleHelper.WriteColoredLine("Geçersiz giriş. Lütfen bir sayı girin.", ConsoleColors.Error); + } + + ConsoleHelper.WriteColoredLine("Çıkış için enter tuşuna basın.", ConsoleColors.Warning); + + Console.ReadLine(); + } + +} \ No newline at end of file diff --git a/quiz-console-app/Services/QuizService.cs b/quiz-console-app/Services/QuizService.cs index c56c3c1..324c4a7 100644 --- a/quiz-console-app/Services/QuizService.cs +++ b/quiz-console-app/Services/QuizService.cs @@ -4,12 +4,13 @@ namespace quiz_console_app.Services; -public class QuizService +public class QuizService { - public List Booklets { get; private set; } - public List AnswerKeys { get; private set; } - + public static List Booklets { get; private set; } + public static List AnswerKeys { get; private set; } + public static List Questions { get; private set; } + private int maxShuffleCount = 10; public QuizService() { Booklets = new List(); @@ -18,40 +19,66 @@ public QuizService() public void GenerateBooklets(List questions, int shuffleCount = 1) { - List shuffledQuestions = new List(); + shuffleCount = Math.Min(shuffleCount, maxShuffleCount); + if (shuffleCount > maxShuffleCount) + ConsoleHelper.WriteColoredLine($"İzin verilen toplam kitapçık sayısı {maxShuffleCount}", ConsoleColors.Warning); + Questions = questions; + + List shuffledQuestions = new List(); + List booklets = new List(); + for (int i = 0; i < shuffleCount; i++) { + char prefix = (char)(65 + i); + string bookletName = $"{prefix}_{1}"; + List bookletQuestions = QuestionShuffler.ShuffleQuestionOptions(questions); BookletViewModel booklet = new BookletViewModel { Id = i + 1, BookletName = $"Booklet {i + 1}", - Questions = bookletQuestions.Select(q => MapToQuestionViewModel(q)).ToList() + Questions = bookletQuestions.Select(q => MapToQuestionViewModel(q)).ToList(), + Prefix = bookletName }; - QuestionShuffler.ShuffleBookletQuestions(booklet); - booklets.Add(booklet); - } Booklets = booklets; } - public void GenerateAnswerKey(List booklets) + public List GenerateAnswerKeys() { List answerKeys = new List(); + foreach (var question in Questions) + { + var correctOption = question.QuestionOptions.FirstOrDefault(option => option.IsCorrect); + + if (correctOption != null) + { + answerKeys.Add(new AnswerKeyViewModel + { + BookletId = 1, + QuestionId = question.Id, + CorrectOptionText = correctOption.Text + }); + } + } - AnswerKeys = answerKeys; + return answerKeys; } + public void EvaluateQuizResults(List userAnswers) + { + + } private static QuestionViewModel MapToQuestionViewModel(Question question) @@ -62,7 +89,8 @@ private static QuestionViewModel MapToQuestionViewModel(Question question) AskText = question.AskText, Explanation = question.Explanation, Difficulty = question.Difficulty, - QuestionOptions = question.QuestionOptions.Select(o => MapToQuestionOptionViewModel(o)).ToList() + QuestionOptions = question.QuestionOptions + .Select(o => MapToQuestionOptionViewModel(o)).ToList() }; } diff --git a/quiz-console-app/ViewModels/AnswerKeyViewModel.cs b/quiz-console-app/ViewModels/AnswerKeyViewModel.cs index 0ea4245..7a5d8db 100644 --- a/quiz-console-app/ViewModels/AnswerKeyViewModel.cs +++ b/quiz-console-app/ViewModels/AnswerKeyViewModel.cs @@ -5,5 +5,5 @@ public class AnswerKeyViewModel public int Id { get; set; } public int BookletId { get; set; } public int QuestionId { get; set; } - public int CorrectOptionId { get; set; } + public string CorrectOptionText { get; set; } } diff --git a/quiz-console-app/ViewModels/BookletViewModel.cs b/quiz-console-app/ViewModels/BookletViewModel.cs index 3d892d2..1fd88d3 100644 --- a/quiz-console-app/ViewModels/BookletViewModel.cs +++ b/quiz-console-app/ViewModels/BookletViewModel.cs @@ -4,5 +4,6 @@ public class BookletViewModel { public int Id { get; set; } public string BookletName { get; set; } + public string Prefix { get; set; } public List Questions { get; set; } } diff --git a/quiz-console-app/ViewModels/UserAnswerKeyViewModel.cs b/quiz-console-app/ViewModels/UserAnswerKeyViewModel.cs new file mode 100644 index 0000000..7499c06 --- /dev/null +++ b/quiz-console-app/ViewModels/UserAnswerKeyViewModel.cs @@ -0,0 +1,9 @@ +namespace quiz_console_app.ViewModels; + +public class UserAnswerKeyViewModel +{ + public int Id { get; set; } + public int BookletId { get; set; } + public int QuestionId { get; set; } + public string UserAnswerOption { get; set; } +}