Assignment-1 OOP Shaik Sameer Roshan
Assignment-1 OOP Shaik Sameer Roshan
UEN: 2024UG100001
Cohort-1
This assignment is a simple learning platform where students can enroll in courses, track their
progress, and earn certificates upon completion. Instructors can create and manage courses, helping
students learn effectively.
The system uses user authentication, course management, and progress tracking to make learning
smooth and organized. It applies concepts like inheritance, encapsulation, and exception handling to
ensure a secure and scalable experience. The system ensures a secure and effective learning
experience, providing a structured and scalable approach to online education and course management.
Requirements
User Authentication:
Users must register with a valid email, name, and password (minimum 6 characters).
Students can enroll in courses, track progress, and earn certificates.
Instructors can create and manage courses.
Course Management:
Instructors can create courses by adding a course ID, title, curriculum, and video content.
Each course has a price, enrollment count, and student reviews (ratings).
Students can search for courses and view details before enrolling.
Student Learning & Progress Tracking:
Students can enroll in courses and make progress.
A progress tracker ensures students complete 100% of the course before receiving a
certificate.
Students can rate courses (1-5 stars) after completion.
Certificate Generation:
Upon course completion, students receive a certificate of completion with their name and
email.
Exception Handling:
InvalidPasswordException: Ensures password meets security requirements.
CourseNotCompletedException: Prevents students from earning a certificate without
completing the course.
Instructor Features:
Instructors can view course statistics, including enrolled students and average ratings.
Instructor can also earn money by enrolling students into their course.
Code
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
// Student Class
class Student extends User {
private List<Course> enrolledCourses = new ArrayList<>();
// Instructor Class
class Instructor extends User {
private List<Course> createdCourses = new ArrayList<>();
public Instructor(String email, String password, String name) {
super(email, password, name);
}
if (role.equals("exit")) {
System.out.println("👋 Exiting the system. Thank you!");
break;
}
if (role.equals("student")) {
while (true) {
System.out.print("\nEnter the course title you're searching for (or type 'exit' to finish): ");
String searchTitle = scanner.nextLine();
if (searchTitle.equalsIgnoreCase("exit")) {
break;
}
Course course = courseManagement.searchCourse(searchTitle);
if (course != null) {
course.displayCourseDetails();
System.out.print("\nDo you want to enroll in this course? (yes/no): ");
String enroll = scanner.nextLine();
if (enroll.equalsIgnoreCase("yes")) {
System.out.println("✅ Payment is done!");
student.enrollInCourse(course);
try {
CourseProgress.simulateProgress(course, scanner);
Certificate.generateCertificate(student, course);
} catch (CourseNotCompletedException e) {
System.out.println(e.getMessage());
}
public Course(String courseId, String title, String instructor, String curriculum, String video, double
price) {
this.courseId = courseId;
this.title = title;
this.instructor = instructor;
this.curriculum = curriculum;
this.video = video;
this.price = price;
}
// Main
public class DigitalLearning {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
CourseManagement courseManagement = new CourseManagement();
courseManagement.addCourse(new Course("C101", "Java Programming", "John Doe", "OOP,
Collections, Streams", "video1.mp4", 49.99));
courseManagement.addCourse(new Course("C102", "Python for Data Science", "Jane Smith",
"Pandas, NumPy, ML Basics", "video2.mp4", 39.99));
courseManagement.addCourse(new Course("C103", "Web Development", "Emily Davis",
"HTML, CSS, JavaScript, React", "video3.mp4", 59.99));
courseManagement.addCourse(new Course("C104", "Data Structures & Algorithms", "Michael
Brown", "Sorting, Graphs, Trees, DP", "video4.mp4", 44.99));
courseManagement.addCourse(new Course("C105", "Cybersecurity Fundamentals", "Lisa
Green", "Ethical Hacking, Encryption", "video5.mp4", 54.99));
courseManagement.addCourse(new Course("C106", "AI & Machine Learning", "David Wilson",
"Neural Networks, Deep Learning, NLP", "video6.mp4", 69.99));
try {
System.out.print("Enter Your Email: ");
String email = scanner.nextLine();
System.out.print("Enter Your Password (min 6 characters): ");
String password = scanner.nextLine();
if (password.length() < 6) {
throw new InvalidPasswordException("❌ Password too short! Must be at least 6
characters.");
}
while (true) {
System.out.print("\nAre you a Student or an Instructor? (student/instructor, or type 'exit' to
quit): ");
String role = scanner.nextLine().toLowerCase();
if (role.equals("exit")) {
System.out.println("👋 Exiting the system. Thank you!");
break;
}
if (role.equals("student")) {
Student student = new Student(email, password, name);
while (true) {
System.out.print("\nEnter the course title you're searching for (or type 'exit' to finish):
");
String searchTitle = scanner.nextLine();
if (searchTitle.equalsIgnoreCase("exit")) {
break;
}
Course course = courseManagement.searchCourse(searchTitle);
if (course != null) {
course.displayCourseDetails();
System.out.print("\nDo you want to enroll in this course? (yes/no): ");
String enroll = scanner.nextLine();
if (enroll.equalsIgnoreCase("yes")) {
System.out.println("✅ Payment is done!");
student.enrollInCourse(course);
try {
CourseProgress.simulateProgress(course, scanner);
Certificate.generateCertificate(student, course);
} catch (CourseNotCompletedException e) {
System.out.println(e.getMessage());
}
}
} else {
System.out.println("⚠ Course Not Found.");
}
}
} else if (role.equals("instructor")) {
Instructor instructor = new Instructor(email, password, name);
instructor.createCourse(courseManagement, scanner);
Student student = new Student(email, password, name);
instructor.viewCourseStats(scanner, courseManagement, student);
} else {
System.out.println("❌ Invalid role! Please enter 'student' or 'instructor'.");
}
}
} catch (InvalidPasswordException e) {
System.out.println(e.getMessage());
} finally {
scanner.close();
}
}
}
Student View Output:
Instructor view output:
Enrolled students & rating view output:
Exception output:
1. InvalidPasswordException
2.CoursenotFoundException
3. CourseNotCompletedException
4.InvalidRoleException:
5. InputMismatchException
Conclusion:
The Java-based Digital Learning System efficiently utilizes Object-Oriented Programming (OOP)
concepts such as encapsulation, inheritance, to ensure secure authentication, structured data handling,
and seamless user interactions. It supports role-based access for students and instructors, allowing
students to search, enroll, and complete courses, while instructors can create and manage courses
efficiently. The system is modular, reusable, and scalable, enabling easy expansion for additional
course types, user roles, and certifications. With robust exception handling, it ensures a smooth and
error-free learning experience