In this lesson, we'll learn how to manage student enrollments using Java's HashMap
and ArrayList
collections. These data structures allow efficient data organization and access, which are essential for building an enrollment system. We'll implement methods to handle enrolling and unenrolling students, checking enrollment status, and listing students in a course. This practical approach will enhance your understanding of these structures. Now, let's dive into the methods we need to implement.
Here are the methods we need to implement in our enrollment system:
enroll(String student, String course)
: This method adds a student to a course. If the student is already enrolled, it does nothing.unenroll(String student, String course)
: This method removes a student from a course. It returnstrue
if the student was enrolled and has now been removed. Otherwise, it returnsfalse
. If, after unenrolling the student, the course becomes empty (no one is enrolled there), remove the course as well.isEnrolled(String student, String course)
: This method checks if a student is enrolled in a course. It returnstrue
if the student is enrolled and otherwise.
