From 747406a5aa957d4a9743d1f29aa8f44579f08c9f Mon Sep 17 00:00:00 2001 From: Zahra Gharagozloo Mazlaghan Date: Mon, 20 Apr 2026 20:44:13 +0330 Subject: [PATCH] Completed the Registration System (With Bonus). --- .idea/.name | 1 + .../RegistrationSystem.java | 39 ++++++++++++++++--- src/CourseRegistrationStarter/Student.java | 3 +- 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 .idea/.name diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..76e4c2a --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Student.java \ No newline at end of file diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..04ae66f 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -1,5 +1,6 @@ package CourseRegistrationStarter; import java.util.ArrayList; +import java.util.Scanner; public class RegistrationSystem { private ArrayList courses; @@ -9,16 +10,44 @@ public class RegistrationSystem { } public void addCourseToSystem(Course c) { - // TODO: Add the course to the system + Scanner scanner = new Scanner(System.in); + + String courseName = scanner.next(); + String courseCode = scanner.next(); + int capacity = scanner.nextInt(); + + Course newCourse = new Course(courseName, courseCode, capacity); + courses.add(newCourse); } public Course findCourseByCode(String code) { - // TODO: Search for a course by course code - // Return the matching course if found, otherwise return null + for (Course i : courses) + { + if (i.getCourseCode().equals(code)) + { + return i; + } + } + return null; + } + + public Course findCourseByName(String name) { + for (Course i : courses) + { + if (i.getCourseCode().equals(name)) + { + return i; + } + } return null; } public void showAllCourses() { - // TODO: Print all courses in the system + for (Course i : courses) + { + System.out.println(i.getCourseName()); + System.out.println(i.getCourseCode()); + System.out.println(i.getCapacity()); + } } -} +} \ No newline at end of file diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..0d7726e 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -21,8 +21,7 @@ public class Student { } public boolean addCourse(Course c) { - // TODO: Register the student in the course if capacity allows - // Return true if registration was successful, otherwise false + return false; }