E-learning Platform
Part of the Object Oriented Programming section of Coddy's C# journey — lesson 68 of 70.
Challenge
EasyLet'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 aLessonclass in theELearning.Modelsnamespace. Each lesson has aTitle(string) andDurationMinutes(int) as read-only properties set through the constructor.Course.cs: Create aCourseclass in theELearning.Modelsnamespace. A course has read-onlyId(string),Title(string), andInstructor(string) properties, plus aLessonslist. Include anAddLesson(Lesson lesson)method and a read-onlyTotalDurationproperty that calculates the sum of all lesson durations.Student.cs: Create aStudentclass in theELearning.Modelsnamespace with read-onlyId(int) andName(string) properties. Students track their progress through a private dictionary that maps course IDs to the number of completed lessons. Include methodsCompleteLesson(string courseId)to increment progress andGetProgress(string courseId)to return the count of completed lessons (or 0 if not enrolled).EnrollmentService.cs: Create anEnrollmentServiceclass in theELearning.Servicesnamespace. This service manages courses and enrollments using private collections. Implement:AddCourse(Course course)- adds a course to the platformEnroll(Student student, string courseId)- returnstrueif enrollment succeeds,falseif the course doesn't exist or student is already enrolledGetEnrolledCourses(Student student)- returns a list of course IDs the student is enrolled inGetCourse(string courseId)- returns the course ornullif 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, orinfo) followed by the course ID
Output formats:
enroll: PrintEnrolled in: {CourseTitle}orEnrollment failed: {courseId}complete: PrintCompleted lesson in {CourseTitle}(increment progress by 1)progress: Print{CourseTitle}: {completed}/{total} lessonsinfo: 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
CS999The 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: CS999Notice 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
1Fundamentals of OOP
External FilesNamespaces & DirectivesIntro to Classes & ObjectsThe 'this' KeywordMethods and ParametersFields vs PropertiesConstructorsObject InitializersRecap - Simple Calculator4Inheritance
Basic Inheritance (:) SyntaxThe 'base' KeywordVirtual & Override KeywordsSealed ClassesThe 'object' Base ClassRecap - Employee Hierarchy7Advanced Features
Operator OverloadingIndexers (this[])ToString() OverrideExtension MethodsRecap - Custom List2Properties & Static Members
Auto-Implemented PropertiesRead/Write-Only PropertiesStatic Fields & MethodsStatic ClassesExpression-Bodied Members5Polymorphism & Interfaces
Compile vs Runtime PolyInterface vs Abstract ClassMultiple InterfacesExplicit InterfacesUpcasting & DowncastingRecap - Shape Calculator