[go: up one dir, main page]

0% found this document useful (0 votes)
11 views18 pages

Assignment-1 OOP Shaik Sameer Roshan

The document outlines a Digital Learning & Certification System that allows students to enroll in courses, track their progress, and earn certificates, while instructors can create and manage courses. It includes features such as user authentication, course management, progress tracking, and exception handling to ensure a secure and effective learning experience. The implementation details cover classes for users, courses, and management, along with exception handling for security and course completion requirements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views18 pages

Assignment-1 OOP Shaik Sameer Roshan

The document outlines a Digital Learning & Certification System that allows students to enroll in courses, track their progress, and earn certificates, while instructors can create and manage courses. It includes features such as user authentication, course management, progress tracking, and exception handling to ensure a secure and effective learning experience. The implementation details cover classes for users, courses, and management, along with exception handling for security and course completion requirements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Name: Shaik Sameer Roshan

UEN: 2024UG100001
Cohort-1

Assignment-1: Digital Learning & Certification System

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.

Implementation Details (Features Implemented):


1. Objects & Classes
 The system will have multiple classes, such as User, Student, Instructor, Course,
CourseManagement, and Certificate.
 Objects will be instantiated for users, courses, and certificates.
2.Encapsulation (Access Specifiers)
 Private attributes such as password, ratings, and enrolledCourses ensure data security and
prevent direct modification.
 Getter and setter methods allow controlled access to private attributes.
3.Exception Handling
 InvalidPasswordException ensures users enter secure passwords of at least six characters.
 CourseNotCompletedException prevents issuing certificates before a course is fully
completed.
4.Nested Classes
 A nested class inside CourseManagement will manage course enrollment and progress
tracking, keeping the main class uncluttered.
5.Static Methods & Variables
 A static method in CourseManagement will return the total number of courses available.
6.Constructors
 Parameterized constructors will be used to initialize user, student, instructor, course, and
certificate objects with relevant data.

Code Explanation & Justification:


User Class
1. public User(String email, String password, String name) {Constructor to initialize user
details}.
2. public String getName() {it will returns the name of the user}.
3. public String getEmail() {it will returns the email of the user}.
Student Class
1. public Student(String email, String password, String name) {Constructor initializes student
details}.
2. public void enrollInCourse(Course course) {it will allows a student to enroll in a course and
also updates the course enrollment count}.
3. public List getEnrolledCourses() {it will returns the list of courses the student is enrolled}.
Instructor Class
1. public Instructor(String email, String password, String name) {Constructor initializes
instructor details.}
2. public void createCourse(CourseManagement courseManagement, Scanner scanner) {Allows
the instructor to create a course with details.}
3. public void viewCourseStats(Scanner scanner, CourseManagement courseManagement,
Student student) {Provides instructors with an overview of their course stats.}
Course Class
1. public Course(String courseId, String title, String instructor, String curriculum, String video,
double price) {Constructor initializes course attributes}.
2. public String getTitle() {it will returns the title of the course.}
3. public double getPrice() {it will returns the price of the course.}
4. public void incrementEnrollment() {Increases the number of enrolled students.}
5. public int getEnrolledStudents() {Returns the total enrolled students.}
6. public void addRating(int rating) {Adds a rating given by a student.}
7. public double getAverageRating(): {Computes the average rating for the course.}
8. public void displayCourseDetails() {Displays course details like title, instructor, curriculum,
and price.}
Course Management Class
1. public void addCourse(Course course) {Adds a course to the course list.}
2. public Course searchCourse(String title) {Searches for a course based on the title.}
Private Fields:
 User - private String password; (Ensures authentication security).
 Student - private List<Course> enrolledCourses;
 Instructor - private List<Course> createdCourses; (Restricts direct modification of created
courses).
 Certificate - private boolean isIssued; (Prevents direct modification of certificate.
Exception Handling in Digital Learning System
 InvalidPasswordException in User Registration – Thrown if the password is less than six
characters.
 CourseNotCompletedException in Course Progress – Thrown if a student tries to get a
certificate without completing 100% of the course.
 InputMismatchException in Course Progress – Catches invalid numeric input when entering
progress percentage or course rating.

Code
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class InvalidPasswordException extends Exception {


public InvalidPasswordException(String message) {
super(message);
}
}

class CourseNotCompletedException extends Exception {


public CourseNotCompletedException(String message) {
super(message);
}
}

// User Class (Common for Student & Instructor)


class User {
protected String name;
protected String email;
protected String password;

public User(String email, String password, String name) {


this.email = email;
this.password = password;
this.name = name;
}
public String getName() {
return name;
}

public String getEmail() {


return email;
}
}

// Student Class
class Student extends User {
private List<Course> enrolledCourses = new ArrayList<>();

public Student(String email, String password, String name) {


super(email, password, name);
}

public void enrollInCourse(Course course) {


enrolledCourses.add(course);
course.incrementEnrollment();
}

public List<Course> getEnrolledCourses() {


return enrolledCourses;
}
}

// Instructor Class
class Instructor extends User {
private List<Course> createdCourses = new ArrayList<>();
public Instructor(String email, String password, String name) {
super(email, password, name);
}

public void createCourse(CourseManagement courseManagement, Scanner scanner) {


System.out.print("\nEnter Course ID: ");
String courseId = scanner.nextLine();

System.out.print("Enter Course Title: ");


String title = scanner.nextLine();

System.out.print("Enter Course Curriculum: ");


String curriculum = scanner.nextLine();

System.out.print("Record Your Video (Type 'start' to begin recording): ");


String video = scanner.nextLine();
if (video.equalsIgnoreCase("start")) {
System.out.println("🎥 Recording in progress...");
while (true) {
System.out.print("Enter 'done' when finished: ");
video = scanner.nextLine();
if (video.equalsIgnoreCase("done")) {
System.out.println("✅ Recording completed!");
break;
}
}
}

System.out.print("Enter Course Price ($): ");


double price = scanner.nextDouble();
scanner.nextLine();
Course newCourse = new Course(courseId, title, name, curriculum, video, price);
courseManagement.addCourse(newCourse);
createdCourses.add(newCourse);

System.out.println("\n✅ Course Created Successfully!");


System.out.println("🚀 Course Launched!");
}

public void viewCourseStats(Scanner scanner, CourseManagement courseManagement, Student


student) {
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")) {
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());
}

System.out.println("\n📊 Updated Instructor Stats:");


System.out.println("Course Title: " + course.getTitle());
System.out.println("Total Enrolled Students: " + course.getEnrolledStudents());
System.out.println("Average Course Rating: " + course.getAverageRating() + "⭐");
}
} else {
System.out.println("⚠ Course Not Found.");
}
}
} else if (role.equals("instructor")) {
System.out.println("\n📊 Your Courses & Stats:");
for (Course course : createdCourses) {
System.out.println("\nCourse Title: " + course.getTitle());
System.out.println("Total Enrolled Students: " + course.getEnrolledStudents());
System.out.println("Average Course Rating: " + course.getAverageRating() + "⭐");
}
} else {
System.out.println("❌ Invalid role! Please enter 'student' or 'instructor'.");
}
}
}
}
// Course Class (To create a new course means to launch a course)
class Course {
private String courseId;
private String title;
private String instructor;
private String curriculum;
private String video;
private double price;
private int enrolledStudents = 0;
private List<Integer> ratings = new ArrayList<>();

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;
}

public String getTitle() {


return title;
}

public double getPrice() {


return price;
}

public void incrementEnrollment() {


enrolledStudents++;
}
public int getEnrolledStudents() {
return enrolledStudents;
}

public void addRating(int rating) {


ratings.add(rating);
}

public double getAverageRating() {


if (ratings.isEmpty()) return 0.0;
return ratings.stream().mapToInt(Integer::intValue).average().orElse(0.0);
}

public void displayCourseDetails() {


System.out.println("\n📌 Course Details:");
System.out.println("Course ID: " + courseId);
System.out.println("Title: " + title);
System.out.println("Instructor: " + instructor);
System.out.println("Curriculum: " + curriculum);
System.out.println("Price: $" + price);
}
}

// Course Management System


class CourseManagement {
private List<Course> courses = new ArrayList<>();

public void addCourse(Course course) {


courses.add(course);
}
public Course searchCourse(String title) {
for (Course course : courses) {
if (course.getTitle().equalsIgnoreCase(title)) {
return course;
}
}
return null;
}
}

// Course Progress Simulation (Up to 100%)


class CourseProgress {
public static void simulateProgress(Course course, Scanner scanner) throws
CourseNotCompletedException {
System.out.println("\nStarting " + course.getTitle() + "...");
System.out.print("👉 Enter how much progress you have completed (0-100%): ");
int progress = scanner.nextInt();
scanner.nextLine(); // Consume newline

if (progress < 100) {


throw new CourseNotCompletedException("\n⛔ Course Not Completed! You completed only
" + progress + "%.");
}

System.out.print("Rate the course (1-5 stars): ");


int rating = scanner.nextInt();
scanner.nextLine();
course.addRating(rating);

System.out.println("\n🎓 Course Completed!");


}
}
// Certificate Generator
class Certificate {
public static void generateCertificate(Student student, Course course) {
System.out.println("\n===============================");
System.out.println("🎉 Certificate of Completion 🎉");
System.out.println("This is to certify that " + student.getName() + " (" + student.getEmail() +
")");
System.out.println("has successfully completed the course:");
System.out.println("\"" + course.getTitle() + "\"");
System.out.println("===============================\n");
}
}

// 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.");
}

System.out.print("Enter Your Name: ");


String name = scanner.nextLine();

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

You might also like