Menu
Coddy logo textTech

E-learning Platform

Part of the Object Oriented Programming section of Coddy's C# journey — lesson 68 of 70.

challenge icon

Challenge

Easy

Let's build an e-learning platform that manages courses, students, and enrollments! This challenge brings together everything you've learned about OOP - classes, inheritance, interfaces, encapsulation, and services working together in a clean architecture.

You'll organize your code across five files:

  • Lesson.cs: Create a Lesson class in the ELearning.Models namespace. Each lesson has a Title (string) and DurationMinutes (int) as read-only properties set through the constructor.
  • Course.cs: Create a Course class in the ELearning.Models namespace. A course has read-only Id (string), Title (string), and Instructor (string) properties, plus a Lessons list. Include an AddLesson(Lesson lesson) method and a read-only TotalDuration property that calculates the sum of all lesson durations.
  • Student.cs: Create a Student class in the ELearning.Models namespace with read-only Id (int) and Name (string) properties. Students track their progress through a private dictionary that maps course IDs to the number of completed lessons. Include methods CompleteLesson(string courseId) to increment progress and GetProgress(string courseId) to return the count of completed lessons (or 0 if not enrolled).
  • EnrollmentService.cs: Create an EnrollmentService class in the ELearning.Services namespace. This service manages courses and enrollments using private collections. Implement:
    • AddCourse(Course course) - adds a course to the platform
    • Enroll(Student student, string courseId) - returns true if enrollment succeeds, false if the course doesn't exist or student is already enrolled
    • GetEnrolledCourses(Student student) - returns a list of course IDs the student is enrolled in
    • GetCourse(string courseId) - returns the course or null if not found
  • Program.cs: Bring everything together by creating courses with lessons, enrolling students, tracking progress, and displaying results based on input.

You will receive the following inputs:

  • Number of courses to create
  • For each course: ID, title, instructor, number of lessons, then for each lesson: title and duration (minutes)
  • Student ID and name
  • Number of operations to perform
  • For each operation: the action (enroll, complete, progress, or info) followed by the course ID

Output formats:

  • enroll: Print Enrolled in: {CourseTitle} or Enrollment failed: {courseId}
  • complete: Print Completed lesson in {CourseTitle} (increment progress by 1)
  • progress: Print {CourseTitle}: {completed}/{total} lessons
  • info: Print {CourseTitle} by {Instructor} - {TotalDuration} minutes

For example, if the inputs are:

2
CS101
Intro to Programming
Dr. Smith
3
Variables
30
Loops
45
Functions
60
CS102
Data Structures
Dr. Jones
2
Arrays
40
Lists
50
1
Alice
6
enroll
CS101
info
CS101
complete
CS101
complete
CS101
progress
CS101
enroll
CS999

The output should be:

Enrolled in: Intro to Programming
Intro to Programming by Dr. Smith - 135 minutes
Completed lesson in Intro to Programming
Completed lesson in Intro to Programming
Intro to Programming: 2/3 lessons
Enrollment failed: CS999

Notice how the service manages the relationship between students and courses, while each class handles its own responsibilities. The student tracks their own progress, courses calculate their total duration, and the enrollment service coordinates everything - a clean separation of concerns!

Try it yourself

using System;
using System.Collections.Generic;
using ELearning.Models;
using ELearning.Services;

class Program
{
    public static void Main(string[] args)
    {
        // Read number of courses
        int numCourses = Convert.ToInt32(Console.ReadLine());
        
        // TODO: Create an EnrollmentService instance
        
        // TODO: Read and create each course with its lessons
        // For each course: read ID, title, instructor, number of lessons
        // For each lesson: read title and duration
        // Add lessons to course, then add course to service
        
        // Read student information
        int studentId = Convert.ToInt32(Console.ReadLine());
        string studentName = Console.ReadLine();
        
        // TODO: Create a Student instance
        
        // Read number of operations
        int numOperations = Convert.ToInt32(Console.ReadLine());
        
        // TODO: Process each operation
        // For each operation: read action and courseId
        // Handle: enroll, complete, progress, info
        // Output the appropriate message based on the action
    }
}

All lessons in Object Oriented Programming