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
EasyLet'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 methodsenroll(Student student)that returns a boolean, andgetEnrolledCount()that returns an int.User.java: Create an abstract base class representing any user on the platform. Include private fields forid(String) andname(String), a constructor that initializes both, appropriate getters, and an abstract methodgetRole()that returns a String describing the user's role.Student.java: Create a class that extendsUser. Add a private ArrayList to track enrolled course IDs. Include a constructor that calls the parent constructor, implementgetRole()to return"Student", and add methodsaddCourse(String courseId)andgetEnrolledCourseCount(). OverridetoString()to return"Student: [name] ([enrolledCount] courses)".Instructor.java: Create a class that extendsUser. Add a private field forspecialty(String). Include a constructor that takes id, name, and specialty, implementgetRole()to return"Instructor", add a getter for specialty, and overridetoString()to return"Instructor: [name] - [specialty]".Course.java: Create a class that implementsEnrollable. Include private fields forcourseId(String),title(String),instructor(Instructor), and an ArrayList of enrolled Students. The constructor takes courseId, title, and instructor. Implementenroll(Student student)to add the student to the list, call the student'saddCourse()method with this course's ID, and return true. ImplementgetEnrolledCount(). Add a methodgetDetails()that returns"[courseId] [title] by [instructorName]".Main.java: Build your platform! You'll receive a comma-separated string of commands:ADD_INSTRUCTOR:id:name:specialtyADD_STUDENT:id:nameADD_COURSE:courseId:title:instructorIdENROLL:studentId:courseIdINFO: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)"
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Object Oriented Programming
1Fundamentals of OOP
External FilesIntroduction to OOPClasses vs ObjectsThe this KeywordMethodsFields (Attributes)Constructor MethodConstructor OverloadingRecap - Simple Calculator4Inheritance
Basic Inheritance (extends)The super KeywordMethod Overriding (@Override)Constructor ChainingThe Object ClassSingle & Multilevel InheritWhy No Multi Class InheritRecap - Employee Hierarchy7Special Methods & Object Class
toString() Methodequals() and hashCode()clone() MethodcompareTo() and ComparableComparator InterfaceRecap - Custom Sorting2Access Modifiers & Encapsulate
Access Levels OverviewGetter and Setter MethodsInformation HidingThe final KeywordRecap - Bank Account Manager5Polymorphism
Method Overloading BasicsMethod Overriding (Run-Time)Upcasting and DowncastingThe instanceof OperatorAbstract Classes and MethodsRecap - Shape Calculator8Advanced OOP Concepts
Composition vs InheritanceAggregation vs CompositionInner Nested & Anonymous ClassEnums and Enum MethodsRecords (Java 16+)Sealed Classes (Java 17+)3Class Props & Static Member
Instance vs Static VariablesStatic MethodsStatic BlocksConstants (static final)Recap - Counter & Utility6Interfaces & Abstract Classes
Introduction to InterfacesImplementing InterfacesMulti Interface ImplemenDefault & Static in InterfaceAbstract Classes vs InterfacesFunctional InterfacesRecap - Payment System