Skip to content

Instantly share code, notes, and snippets.

@wahidustoz
Last active July 5, 2025 03:13
Show Gist options
  • Select an option

  • Save wahidustoz/78b7077d5aa3ea24c5fb144c316828d9 to your computer and use it in GitHub Desktop.

Select an option

Save wahidustoz/78b7077d5aa3ea24c5fb144c316828d9 to your computer and use it in GitHub Desktop.
Quiz Engine | C# Project

๐Ÿ“š Quiz engine

Build a twoโ€‘mode console appโ€”Teacher and Studentโ€”that creates, manages, and runs quizzes, using Spectre.Console for all user interaction.

New in this version

  • Teacher Mode can disable / enable or delete existing quizzes.
  • Optional timeโ€‘limited questions feature worth +50 bonus points.

๐Ÿ—‚ Table of Contents

  1. Objective
  2. Functional Requirements
  3. Nonโ€‘Functional Requirements
  4. Folder Structure
  5. Data Model (Mermaid)
  6. Sample Quiz JSON
  7. Console I/Oย Samples
  8. Edge Cases
  9. Spectre.Console Usage Requirements
  10. Task Breakdown
  11. Evaluation Rubric
  12. Sequence Diagrams

๐ŸŽฏ 1ย Objective

Create a console application that lets:

  • Teachers

    1. Build quizzes (MCQ, True/False, Short Answer).
    2. Enable/disable quizzes (disabled quizzes are hidden from students).
    3. Delete quizzes with confirmation.
  • Students

    1. Load an active quiz.
    2. Answer questions via SelectionPrompt / TextPrompt.
    3. Receive an autoโ€‘graded report, with optional halfโ€‘score logic for questions answered after their time limit.

โœ… 2ย Functional Requirements

๐Ÿ‘ฉโ€๐Ÿซ Teacher Mode

Requirement Detail
Main menu SelectionPrompt: Createย Quiz, Manageย Quizzes, Exit.
Create quiz Enter title & description via TextPrompt.
Add questions MCQ, True/False, Short Answer; repeat until done.
MCQ format Options must be dictionary: "A": "int", etc. Answer stores the key (e.g., "A").
Timeโ€‘limited (optional) Teacher may set TimeLimitSeconds (โ‰ฅโ€ฏ5โ€ฏs). Omit for unlimited.
Validation Reject empty prompts, duplicate option keys, invalid time limits.
Summary & save Show a Table; confirm via ConfirmationPrompt before writing JSON.
Manage quizzes List all JSON files via SelectionPrompt. After selection: Enable/Disable, Delete, View Summary.
Delete Requires two confirmations.

๐Ÿ‘ฆ Student Mode

Requirement Detail
Quiz list Show only enabled .json files via SelectionPrompt.
Load & header Display in a Panel.
Question flow โ€ข MCQ / Trueโ€‘False: SelectionPrompt (arrow keys +โ€ฏEnter).
โ€ข Short Answer: TextPrompt.
Timeโ€‘limited logic (bonus) If a question has TimeLimitSeconds, start a countdown.
โ€ข Correct within limit โ†’ full point.
โ€ข Correct after limit โ†’ ยฝย point.
โ€ข No answer or wrong answer โ†’ 0.
Scoring Autoโ€‘update points (1, 0.5, 0).
Report Table with โœ”/โœ– and โฑ icons; overall % and pass/fail (70โ€ฏ% threshold).

๐Ÿšซ 3ย Nonโ€‘Functional Requirements

  • 100โ€ฏ% Spectre.Console for input/outputโ€”no Console.ReadLine/WriteLine.
  • Robust error handling with custom exceptions where appropriate.
  • Disabled quizzes must not appear in Student Mode.

๐Ÿ—‚ 4ย Folder Structure

QuizApp/
โ”‚
โ”œโ”€โ”€ Program.cs
โ”œโ”€โ”€ Models/
โ”‚   โ”œโ”€โ”€ Question.cs
โ”‚   โ”œโ”€โ”€ McqQuestion.cs
โ”‚   โ”œโ”€โ”€ TrueFalseQuestion.cs
โ”‚   โ”œโ”€โ”€ ShortAnswerQuestion.cs
โ”‚   โ””โ”€โ”€ QuizMeta.cs          <-- holds Title, Description, IsActive
โ”‚
โ”œโ”€โ”€ Services/
โ”‚   โ”œโ”€โ”€ QuizBuilder.cs
โ”‚   โ”œโ”€โ”€ QuizManager.cs       <-- enable/disable/delete logic
โ”‚   โ”œโ”€โ”€ QuizRunner.cs
โ”‚   โ””โ”€โ”€ QuizStorage.cs
โ”‚
โ”œโ”€โ”€ Utilities/
โ”‚   โ””โ”€โ”€ InputHelper.cs
โ”‚
โ””โ”€โ”€ Data/
    โ””โ”€โ”€ quizzes/

๐Ÿ— 5ย Data Model

classDiagram
    direction TB
    class QuizMeta {
        +string Title
        +string Description
        +bool IsActive
        +List~Question~ Questions
    }

    class Question {
        +string Prompt
        +int? TimeLimitSeconds
        +abstract double CheckAnswer(string answer, double elapsedSec)
    }

    class McqQuestion {
        +Dictionary~string,string~ Options
        +string AnswerKey
    }

    class TrueFalseQuestion {
        +bool CorrectAnswer
    }

    class ShortAnswerQuestion {
        +string CorrectAnswer
    }

    QuizMeta *-- Question
    Question <|-- McqQuestion
    Question <|-- TrueFalseQuestion
    Question <|-- ShortAnswerQuestion
Loading

๐Ÿ“‘ 6ย Sample Quiz JSON (timeโ€‘limit demo)

{
  "Title": "C# Basics",
  "Description": "Covers primitive types and control flow.",
  "IsActive": true,
  "Questions": [
    {
      "Type": "MCQ",
      "Prompt": "Which is a value type in C#?",
      "Options": {
        "A": "string",
        "B": "int",
        "C": "object",
        "D": "dynamic"
      },
      "Answer": "B",
      "TimeLimitSeconds": 20   // answer in 20โ€ฏs for full credit
    },
    {
      "Type": "TrueFalse",
      "Prompt": "The 'var' keyword implies dynamic typing.",
      "CorrectAnswer": false
    },
    {
      "Type": "ShortAnswer",
      "Prompt": "What keyword defines a constant?",
      "CorrectAnswer": "const",
      "TimeLimitSeconds": 15
    }
  ]
}

๐Ÿ’ป 7ย Consoleย I/Oย Samples

Teacher Mode โ€“ Manage Quizzes

[ Manage Existing Quizzes ]
โฏ C# Basics   (active)
  OOP Review   (disabled)
Actions for **C# Basics**
โฏ Disable Quiz
  Delete Quiz
  View Summary
  Back

Student Mode โ€“ Timeโ€‘Limited Question

[ Question 1 of 3 ]  โฑ 20s
Which is a value type in C#?

โฏ A: string
  B: int
  C: object
  D: dynamic

(timer counts down; answer after 22โ€ฏs but correct)
โš  Time exceeded. Half credit awarded.


โš  8ย Edgeย Cases

  • Attempting to start Student Mode when no active quizzes exist.
  • Deleting a quiz that is currently disabled.
  • Teacher disabling an already disabled quiz.
  • Time limit โ‰คโ€ฏ0 or <โ€ฏ5โ€ฏseconds (reject).
  • Student presses Esc or closes prompt before answering (treat as wrong).
  • Halfโ€‘credit rounding (0.5 increments).

๐Ÿ–ผ 9ย Spectre.Console Usage Requirements

Purpose API
Main & subโ€‘menus SelectionPrompt<string>()
Confirmations ConfirmationPrompt()
Text input TextPrompt<string>()
Timer display LiveDisplay, Status(), or custom markup refresh
Tables Table()
Panels / headings Panel(), Rule()
Color feedback Markup()

โฑ 10ย Task Breakdown (โ‰ˆโ€ฏ16ย hrs core + 2โ€‘3โ€ฏhrs bonus)

Task Hours
Design models & interfaces 2
Implement Teacher Mode (create) 3
Implement Teacher Mode (manage) 1
Implement Student Mode 4
JSON save/load layer 2
Spectre polishing 2
Edge case handling & tests 2
Bonus: timeโ€‘limit engine +2โ€“3

๐Ÿงพ 11ย Evaluationย Rubricย /150

Area Points
OOP design & readability 15
Teacher Mode โ€“ create 15
Teacher Mode โ€“ manage 10
Student Mode 15
JSON persistence reliability 15
Full Spectre.Console usage 15
Error/edge handling 15
All mandatory edge cases met 15
Bonus: timeโ€‘limit questions +50

(Maxโ€ฏ=โ€ฏ150; graders scale to 100ย % for final grade.)


๐Ÿ”„ 12ย Sequenceย Diagrams

12.1ย Teacher Mode (Create / Manage)

sequenceDiagram
    participant T as Teacher
    participant App as ConsoleApp
    participant FS as FileSystem

    T->>App: Launch Teacher Mode
    App-->>T: Main menu (Create / Manage)
    alt Create Quiz
        App-->>T: Prompt meta
        loop Add Qs
            App-->>T: Select qโ€‘type
            T-->>App: Provide details
        end
        App-->>T: Show summary -> confirm save
        T-->>App: Confirm
        App->>FS: Write JSON
        FS-->>App: OK
    else Manage Quiz
        App->>FS: List quizzes
        FS-->>App: File list
        App-->>T: Select quiz
        T-->>App: Choose Disable/Delete/View
        alt Disable
            App->>FS: Toggle IsActive
        else Delete
            App-->>T: Confirm x2
            T-->>App: Confirm
            App->>FS: Delete file
        end
    end
    App-->>T: Result message
Loading

12.2ย Student Mode (with Time Limit)

sequenceDiagram
    participant S as Student
    participant App as ConsoleApp
    participant FS as FileSystem
    S->>App: Launch Student Mode
    App->>FS: List active quizzes
    FS-->>App: Quiz list
    App-->>S: Select quiz
    S-->>App: Choose
    App->>FS: Read JSON
    FS-->>App: Quiz data
    loop Each question
        App-->>S: Show prompt (+timer if set)
        App-->>S: SelectionPrompt/TextPrompt
        S-->>App: Answer (and elapsed time)
        App-->>S: Evaluate โœ” / โœ– / โฑยฝ
    end
    App-->>S: Display final report
Loading

13โ€ฏย Endโ€‘toโ€‘Endย I/Oย Examples

The following transcripts demonstrate every realistic branch the user can take in Teacher and Student modes, including success paths, validation errors, confirmation prompts, disabled quizzes, timeโ€‘limited questions, half credit, and โ€œno active quizโ€ handling.
All prompts are powered by Spectre.Console components (shown inย bold).

13.1ย Teacherย Modeย โ€“ย Fullย Cycle

A.ย Create a New Quiz (happy path)
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  TEACHER MODE  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โฏ Create Quiz
  Manage Quizzes
  Exit
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

[ Title of new quiz ]           (TextPrompt)
> C# Basics

[ Short description ]           (TextPrompt)
> Covers primitive types and control flow.

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Add questions to โ€œC# Basicsโ€
โฏ Add MCQ
  Add True/False
  Add Short Answer
  Finish Quiz
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

(After choosing Add MCQ)

[ Question prompt ]             (TextPrompt)
> Which is a value type in C#?

[ Option A ]                    (TextPrompt)
> string
[ Option B ]
> int
[ Option C ]
> object
[ Option D ]
> dynamic

[ Correct option key ]          (SelectionPrompt) 
โฏ A
  B
  C
  D
(Teacher moves to B)  Enter

[ Time limit in seconds (ENTER for none) ]   (TextPrompt)
> 20

โœ” MCQ added.

(Add True/False, Add Short Answer โ€ฆ)

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
All questions entered.  Summary:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ #   โ”‚ Type            โ”‚ Prompt                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1   โ”‚ MCQ (20โ€ฏs)      โ”‚ Which is a value type in C#?          โ”‚
โ”‚ 2   โ”‚ True/False      โ”‚ 'var' implies dynamic typing.         โ”‚
โ”‚ 3   โ”‚ Short Answer    โ”‚ Keyword that defines a constant?      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Save quiz?                     (ConfirmationPrompt)  [y/N]
> y

๐Ÿ—‚ Writing file โ€œC#ย Basics.jsonโ€ โ€ฆ done.
[green]Quiz created successfully![/]
B.ย Validation Error โ€” Duplicate MCQ Option Key
Add MCQ
[ Option A ]
> int
[ Option A ]  (again by mistake)
> integer
[red]Duplicate option key โ€œAโ€. Option keys must be unique (Aโ€‘Z).[/]
C.ย Overwrite Existing Quiz โ€”ย Decline
Quiz titled โ€œC# Basicsโ€ already exists.
Overwrite?  (ConfirmationPrompt) [y/N]
> n
[grey]File not overwritten. Returning to main menuโ€ฆ[/]
D.ย Manage Quizzes โ€”ย Disable, Enable, Delete
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  MANAGE QUIZZES  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โฏ C# Basics         (active)
  OOP Review        (disabled)
  Back
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

(Select โ€œC#ย Basicsโ€)

Actions:                      (SelectionPrompt)
โฏ Disable Quiz
  Delete Quiz
  View Summary
  Back

> Disable Quiz
Confirm disable โ€œC#ย Basicsโ€?  (ConfirmationPrompt) [y/N]
> y
[green]Quiz disabled.[/]

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  MANAGE QUIZZES  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  C# Basics         (disabled)
โฏ OOP Review        (disabled)
  Back

(Select โ€œOOPย Reviewโ€)

Actions:
โฏ Enable Quiz
  Delete Quiz
  View Summary
  Back

> Enable Quiz
[green]Quiz enabled.[/]

(Delete flow)

Actions:
  Enable/Disable
โฏ Delete Quiz

Danger! This will permanently delete โ€œC#ย Basicsโ€.
Type DELETE to confirm โ†’  
> del
[red]Incorrect confirmation string. Delete aborted.[/]

Type DELETE to confirm โ†’  
> DELETE
Are you absolutely sure?  (ConfirmationPrompt) [y/N]
> y
File removed.

13.2ย Studentย Modeย โ€“ย Fullย Cycle

E.ย No Active Quizzes
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  STUDENT MODE  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
(no active quizzes found)
Ask your teacher to enable at least one quiz.
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
F.ย Take Quiz โ€“ย Mixed Results + Time Limit Scenarios
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  STUDENT MODE  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Select a quiz:                (SelectionPrompt)
โฏ C# Basics
  OOP Review
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  C# Basics                                โ”‚
โ”‚  Covers primitive types and control flow. โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Press ENTER to beginโ€ฆ

[ Question 1 / 3 | โฑ 20โ€ฏs ]
Which is a value type in C#?
โฏ A: string
  B: int
  C: object
  D: dynamic
(Answer chosen within 12โ€ฏs โ†’ B)  
[green]โœ” Correct![/]

[ Question 2 / 3 ]
'var' implies dynamic typing.
โฏ True
  False
(Selected โ€œTrueโ€)  
[red]โœ– Incorrect.[/]

[ Question 3 / 3 | โฑ 15โ€ฏs ]
Keyword that defines a constant?
(15โ€‘second countdown shown with Status spinner)
> const
(Time taken: 19โ€ฏs)  
[yellow]โš  Time exceeded. Half credit awarded.[/]

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  RESULTS  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”Œโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ #   โ”‚ Question                         โ”‚ Score   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1   โ”‚ value type in C#?                โ”‚ [green]1.0[/] โ”‚
โ”‚ 2   โ”‚ 'var' implies dynamic typing.    โ”‚ [red]0.0[/]  โ”‚
โ”‚ 3   โ”‚ keyword for constant             โ”‚ [yellow]0.5[/]โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Total: 1.5 / 3  (50โ€ฏ%) โ†’ [red]Fail[/]
G.ย Invalid Selection Key (Prevented by UI)

Because MCQ and True/False use SelectionPrompt, the user cannot enter an invalid keyโ€”arrow keys restrict the choice set.
If they press Esc or CTRLโ€‘C, you should catch the OperationCanceledException and treat the answer as wrongย (0โ€ฏpts).

[ Question 1 / 3 ]
Which is a value type in C#?
(ESC pressed)
[grey]No answer selected. Marked as incorrect.[/]

These exhaustive transcripts cover all paths that must be handled in code.
Good luck, and happy coding! ๐Ÿš€

@wahidustoz
Copy link
Author

wahidustoz commented Jul 5, 2025

๐Ÿ‘ฉโ€๐Ÿซ Teacher Mode โ€” How QuizBuilder and QuizManager Work


๐Ÿšช Entry Point

When the user selects "Teacher Mode" from the main menu:

new QuizBuilder().Run();

๐Ÿงฉ Role of QuizBuilder

QuizBuilder acts as the controller for Teacher Mode.
It routes the teacher to either creating or managing quizzes.

๐Ÿงญ Main Menu Prompt

public void Run()
{
    while (true)
    {
        var choice = InputHelper.AskSelection("Teacher Menu", new[]
        {
            "โž• Create New Quiz",
            "๐Ÿ›  Manage Existing Quizzes",
            "๐Ÿ”™ Back to Main Menu"
        });

        switch (choice)
        {
            case "โž• Create New Quiz":
                CreateQuiz(); // Handles new quiz creation
                break;

            case "๐Ÿ›  Manage Existing Quizzes":
                new QuizManager().Run(); // Delegates to QuizManager
                break;

            case "๐Ÿ”™ Back to Main Menu":
                return;
        }
    }
}

๐Ÿ—๏ธ What CreateQuiz() Does

Inside QuizBuilder, the CreateQuiz() method:

  • Prompts for:
    • โœ… Quiz Title (TextPrompt)
    • โœ… Description (TextPrompt)
  • Creates an empty QuizMeta object
  • Starts a loop to add questions:
    • MCQ
    • True/False
    • Short Answer
  • Validates all entries
  • Offers optional time limits
  • Renders a Table summary
  • Confirms saving via ConfirmationPrompt
  • Calls QuizStorage.Save() to write JSON

๐Ÿ”ง What QuizManager.Run() Does

Once the teacher selects "Manage Existing Quizzes",
control is passed to QuizManager:

Responsibilities:

  • List all quizzes from Data/quizzes/
  • Let the user:
    • โœ… Enable/Disable selected quiz
    • โŒ Delete a quiz (with 2 confirmations)
    • ๐Ÿ“„ View Summary in a table
  • Update the quiz metadata (IsActive flag)
  • Remove file if deleted

๐Ÿ” Diagram โ€” Teacher Mode Lifecycle

flowchart TD
    A[Start: Teacher Mode Selected]
    B[QuizBuilder.Run]
    C[Main Menu: SelectionPrompt]
    D[CreateQuiz]
    E[QuizManager.Run]
    F[Return to Main Menu]

    A --> B --> C
    C --> D
    C --> E
    C --> F

    D --> D1[Prompt for title + description]
    D1 --> D2[Loop: Add Questions]
    D2 --> D3[Show summary table]
    D3 --> D4[Confirm and Save as JSON]

    E --> E1[List all quizzes]
    E1 --> E2[Select quiz to manage]
    E2 --> E3[Action: Enable/Disable/Delete/View]
    E3 --> E4[Perform selected action]
    E3 --> F

Loading

๐ŸŽฏ Why Split the Logic?

Class Responsibility
QuizBuilder Create new quizzes from scratch
QuizManager Manage existing quizzes

โœ… Benefits:

  • Clear separation of concerns (SRP)
  • Better readability and maintenance
  • Easier to test independently

Let me know if you'd like this shown as a Mermaid diagram too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment