forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
88 changed files
with
2,783 additions
and
1,402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,163 +1,23 @@ | ||
# Designing a University Course Registration System | ||
|
||
In this article, we explore the object-oriented design and implementation of a University Course Registration System using Java. | ||
|
||
The system facilitates course registration and management for students and universities. | ||
|
||
## System Requirements | ||
|
||
The University Course Registration System should: | ||
|
||
1. **Student Management**: Handle student profiles and academic records. | ||
2. **Course Management**: Manage course details, schedules, and capacities. | ||
3. **Registration Process**: Enable students to register for courses. | ||
4. **Prerequisite Checking**: Ensure students meet course prerequisites. | ||
5. **Enrollment Verification**: Confirm student enrollments in courses. | ||
|
||
## Core Use Cases | ||
|
||
1. **Registering and Managing Student Profiles** | ||
2. **Adding and Updating Courses** | ||
3. **Enrolling in Courses** | ||
4. **Checking Prerequisites** | ||
5. **Verifying Course Enrollment** | ||
|
||
## UML/Class Diagrams | ||
|
||
Key Classes: | ||
|
||
- `CourseRegistrationSystem`: Manages the system. | ||
- `Student`: Represents a student. | ||
- `Course`: Represents a university course. | ||
- `Enrollment`: Manages student enrollments. | ||
|
||
## Java Implementation | ||
|
||
### Student Class | ||
|
||
Manages student information and enrollment records. | ||
|
||
```java | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class Student { | ||
private String studentId; | ||
private String name; | ||
private Set<String> completedCourses; | ||
private Set<Enrollment> enrollments; | ||
|
||
public Student(String studentId, String name) { | ||
this.studentId = studentId; | ||
this.name = name; | ||
this.completedCourses = new HashSet<>(); | ||
this.enrollments = new HashSet<>(); | ||
} | ||
|
||
public void enrollInCourse(Course course) { | ||
if (course.checkPrerequisites(completedCourses)) { | ||
Enrollment newEnrollment = new Enrollment(this, course); | ||
enrollments.add(newEnrollment); | ||
course.addStudent(this); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public void addCompletedCourse(String courseId) { | ||
completedCourses.add(courseId); | ||
} | ||
|
||
// Getters and setters... | ||
} | ||
``` | ||
### Course Class | ||
Represents a university course. | ||
```java | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class Course { | ||
private String courseId; | ||
private String title; | ||
private int capacity; | ||
private Set<String> prerequisites; | ||
private Set<Student> studentsEnrolled; | ||
|
||
public Course(String courseId, String title, int capacity) { | ||
this.courseId = courseId; | ||
this.title = title; | ||
this.capacity = capacity; | ||
this.prerequisites = new HashSet<>(); | ||
this.studentsEnrolled = new HashSet<>(); | ||
} | ||
|
||
public boolean addStudent(Student student) { | ||
if (studentsEnrolled.size() < capacity) { | ||
studentsEnrolled.add(student); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public void addPrerequisite(String prerequisiteCourseId) { | ||
prerequisites.add(prerequisiteCourseId); | ||
} | ||
|
||
public boolean checkPrerequisites(Set<String> completedCourses) { | ||
return completedCourses.containsAll(prerequisites); | ||
} | ||
// Getters and setters... | ||
} | ||
``` | ||
### Enrollment Class | ||
Manages a student's enrollment in a course. | ||
```java | ||
public class Enrollment { | ||
private Student student; | ||
private Course course; | ||
|
||
public Enrollment(Student student, Course course) { | ||
this.student = student; | ||
this.course = course; | ||
} | ||
|
||
// Getters and setters... | ||
} | ||
``` | ||
### CourseRegistrationSystem Class | ||
Manages the course registration system operations. | ||
```java | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CourseRegistrationSystem { | ||
private List<Student> students; | ||
private List<Course> courses; | ||
|
||
public CourseRegistrationSystem() { | ||
this.students = new ArrayList<>(); | ||
this.courses = new ArrayList<>(); | ||
} | ||
|
||
public void addStudent(Student student) { | ||
students.add(student); | ||
} | ||
|
||
public void addCourse(Course course) { | ||
courses.add(course); | ||
} | ||
|
||
public boolean registerStudentForCourse(String studentId, String courseId) { | ||
Student student = findStudentById(studentId); | ||
Course course = findCourseById(courseId); | ||
|
||
if (student != null && course != null) { | ||
return student.enrollInCourse(course); | ||
} | ||
return false; | ||
} | ||
|
||
// Other necessary methods... | ||
} | ||
``` | ||
## Requirements | ||
1. The course registration system should allow students to register for courses and view their registered courses. | ||
2. Each course should have a course code, name, instructor, and maximum enrollment capacity. | ||
3. Students should be able to search for courses based on course code or name. | ||
4. The system should prevent students from registering for courses that have reached their maximum enrollment capacity. | ||
5. The system should handle concurrent registration requests from multiple students. | ||
6. The system should ensure data consistency and prevent race conditions. | ||
7. The system should be extensible to accommodate future enhancements and new features. | ||
|
||
### Java Implementation | ||
[Full Code](../solutions/java/src/courseregistrationsystem/) | ||
|
||
1. The Student class represents a student in the course registration system, with properties such as ID, name, email, and a list of registered courses. | ||
2. The Course class represents a course offered in the system, with properties such as code, name, instructor, maximum capacity, and the number of enrolled students. | ||
3. The Registration class represents a registration record, associating a student with a course and capturing the registration timestamp. | ||
4. The CourseRegistrationSystem class is the main class that manages the course registration system. It follows the Singleton pattern to ensure only one instance of the system exists. | ||
5. The CourseRegistrationSystem class provides methods for adding courses and students, searching for courses, registering students for courses, and retrieving registered courses for a student. | ||
6. Multi-threading is implemented using concurrent data structures (ConcurrentHashMap and CopyOnWriteArrayList) to handle concurrent access to shared data, such as courses and registrations. | ||
7. The registerCourse method is synchronized to ensure thread safety when multiple students are registering for courses simultaneously. | ||
8. The notifyObservers method is a placeholder for notifying observers (e.g., UI components) about updates to course enrollment. | ||
9. The CourseRegistrationDemo class demonstrates the usage of the course registration system by creating courses and students, searching for courses, registering students for courses, and retrieving registered courses for a student. |
Oops, something went wrong.