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.
The University Course Registration System should:
- Student Management: Handle student profiles and academic records.
- Course Management: Manage course details, schedules, and capacities.
- Registration Process: Enable students to register for courses.
- Prerequisite Checking: Ensure students meet course prerequisites.
- Enrollment Verification: Confirm student enrollments in courses.
- Registering and Managing Student Profiles
- Adding and Updating Courses
- Enrolling in Courses
- Checking Prerequisites
- Verifying Course Enrollment
Key Classes:
CourseRegistrationSystem
: Manages the system.Student
: Represents a student.Course
: Represents a university course.Enrollment
: Manages student enrollments.
Manages student information and enrollment records.
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...
}
Represents a university course.
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...
}
Manages a student's enrollment in a course.
public class Enrollment {
private Student student;
private Course course;
public Enrollment(Student student, Course course) {
this.student = student;
this.course = course;
}
// Getters and setters...
}
Manages the course registration system operations.
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...
}