Menu
Coddy logo textTech

E-Learning Platform

Part of the Object Oriented Programming section of Coddy's Java journey — lesson 84 of 87.

Welcome to the Final Challenges chapter! These challenges are designed to test your mastery of all the OOP concepts you've learned throughout this course.

In this challenge, you'll build an E-Learning Platform system that combines inheritance, interfaces, polymorphism, encapsulation, and design patterns into a cohesive application.

Your platform should model the relationships between courses, students, and instructors. Think about how a User base class can be extended by Student and Instructor classes, how courses contain lessons, and how enrollment tracking works between students and courses.

Consider which OOP principles apply: use encapsulation to protect user data, inheritance to share common behavior, interfaces to define contracts like Enrollable or Completable, and polymorphism to handle different user types uniformly.

Good luck applying everything you've learned!

challenge icon

Challenge

Easy

Let's build an E-Learning Platform that brings together all the OOP concepts you've mastered throughout this course! You'll create a system that models the relationships between courses, students, and instructors using inheritance, interfaces, polymorphism, and encapsulation.

You'll organize your code across six files:

  • Enrollable.java: Create an interface that defines the contract for enrollment operations. It should declare methods enroll(Student student) that returns a boolean, and getEnrolledCount() that returns an int.
  • User.java: Create an abstract base class representing any user on the platform. Include private fields for id (String) and name (String), a constructor that initializes both, appropriate getters, and an abstract method getRole() that returns a String describing the user's role.
  • Student.java: Create a class that extends User. Add a private ArrayList to track enrolled course IDs. Include a constructor that calls the parent constructor, implement getRole() to return "Student", and add methods addCourse(String courseId) and getEnrolledCourseCount(). Override toString() to return "Student: [name] ([enrolledCount] courses)".
  • Instructor.java: Create a class that extends User. Add a private field for specialty (String). Include a constructor that takes id, name, and specialty, implement getRole() to return "Instructor", add a getter for specialty, and override toString() to return "Instructor: [name] - [specialty]".
  • Course.java: Create a class that implements Enrollable. Include private fields for courseId (String), title (String), instructor (Instructor), and an ArrayList of enrolled Students. The constructor takes courseId, title, and instructor. Implement enroll(Student student) to add the student to the list, call the student's addCourse() method with this course's ID, and return true. Implement getEnrolledCount(). Add a method getDetails() that returns "[courseId] [title] by [instructorName]".
  • Main.java: Build your platform! You'll receive a comma-separated string of commands:
    • ADD_INSTRUCTOR:id:name:specialty
    • ADD_STUDENT:id:name
    • ADD_COURSE:courseId:title:instructorId
    • ENROLL:studentId:courseId
    • INFO:userId

    Maintain collections of instructors, students, and courses. Process each command and print:

    • ADD_INSTRUCTOR: Instructor added: [name]
    • ADD_STUDENT: Student added: [name]
    • ADD_COURSE: Course added: [title]
    • ENROLL: [studentName] enrolled in [courseTitle]
    • INFO: Print the user's toString() output

    After all commands, print --- Platform Summary --- followed by each course's details and enrollment count in the format [courseDetails] - [count] student(s).

You will receive one input: the comma-separated command string.

For example, with input ADD_INSTRUCTOR:I001:Dr. Smith:Java,ADD_STUDENT:S001:Alice,ADD_STUDENT:S002:Bob,ADD_COURSE:C001:OOP Fundamentals:I001,ENROLL:S001:C001,ENROLL:S002:C001,INFO:S001,INFO:I001, your output would be:

Instructor added: Dr. Smith
Student added: Alice
Student added: Bob
Course added: OOP Fundamentals
Alice enrolled in OOP Fundamentals
Bob enrolled in OOP Fundamentals
Student: Alice (1 courses)
Instructor: Dr. Smith - Java
--- Platform Summary ---
[C001] OOP Fundamentals by Dr. Smith - 2 student(s)

This challenge combines inheritance (User hierarchy), interfaces (Enrollable), polymorphism (different user types with their own toString implementations), and encapsulation (private fields with controlled access) into a cohesive system!

Cheat sheet

This final challenge combines multiple OOP concepts into a cohesive system:

Interfaces

Define contracts for behavior that classes must implement:

public interface Enrollable {
    boolean enroll(Student student);
    int getEnrolledCount();
}

Abstract Classes

Create base classes with shared behavior and abstract methods:

public abstract class User {
    private String id;
    private String name;
    
    public User(String id, String name) {
        this.id = id;
        this.name = name;
    }
    
    public abstract String getRole();
}

Inheritance

Extend base classes to create specialized types:

public class Student extends User {
    private ArrayList<String> enrolledCourses;
    
    public Student(String id, String name) {
        super(id, name);
        this.enrolledCourses = new ArrayList<>();
    }
    
    @Override
    public String getRole() {
        return "Student";
    }
}

Implementing Interfaces

Classes can implement interfaces to fulfill contracts:

public class Course implements Enrollable {
    private ArrayList<Student> enrolledStudents;
    
    @Override
    public boolean enroll(Student student) {
        enrolledStudents.add(student);
        student.addCourse(courseId);
        return true;
    }
    
    @Override
    public int getEnrolledCount() {
        return enrolledStudents.size();
    }
}

Polymorphism

Different classes can override methods to provide specialized behavior:

@Override
public String toString() {
    return "Student: " + name + " (" + enrolledCourses.size() + " courses)";
}

Encapsulation

Use private fields with controlled access through methods to protect data integrity and maintain relationships between objects.

Try it yourself

import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        
        // TODO: Create collections to store instructors, students, and courses
        // Hint: Use HashMap with id as key for easy lookup
        
        // TODO: Split input by comma to get individual commands
        
        // TODO: Process each command:
        // - ADD_INSTRUCTOR:id:name:specialty -> Create instructor, add to collection, print "Instructor added: [name]"
        // - ADD_STUDENT:id:name -> Create student, add to collection, print "Student added: [name]"
        // - ADD_COURSE:courseId:title:instructorId -> Create course with instructor, add to collection, print "Course added: [title]"
        // - ENROLL:studentId:courseId -> Enroll student in course, print "[studentName] enrolled in [courseTitle]"
        // - INFO:userId -> Find user (student or instructor) and print their toString()
        
        // TODO: After processing all commands, print "--- Platform Summary ---"
        
        // TODO: For each course, print "[courseDetails] - [count] student(s)"
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Object Oriented Programming