From e8bafc4140fb5ac684b2d320a1f64dcc467c990f Mon Sep 17 00:00:00 2001 From: Bita Date: Mon, 20 Apr 2026 22:40:21 +0330 Subject: [PATCH 1/3] changes in class Student --- src/CourseRegistrationStarter/Student.java | 50 +++++++++++++++++----- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..e97d1c9 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -1,12 +1,15 @@ package CourseRegistrationStarter; import java.util.ArrayList; -public class Student { +public class Student +{ private String name; private String studentId; private ArrayList registeredCourses; + private int limit = 15; - public Student(String name, String studentId) { + public Student(String name, String studentId) + { this.name = name; this.studentId = studentId; this.registeredCourses = new ArrayList<>(); @@ -20,20 +23,45 @@ public class Student { return studentId; } - public boolean addCourse(Course c) { - // TODO: Register the student in the course if capacity allows - // Return true if registration was successful, otherwise false + public boolean addCourse(Course c) + { + if(registeredCourses.contains(c) || c.getCapacity() == 0) + { + return false; + } + else if(registeredCourses.size() <= limit && c.getCapacity() > 0) + { + c.reduceCapacity(); + registeredCourses.add(c); + return true; + } return false; } - public boolean dropCourse(Course c) { - // TODO: Remove the course from the student's list - // Restore the course capacity if removal was successful - // Return true if the course was dropped, otherwise false + public boolean dropCourse(Course c) + { + if(registeredCourses.contains(c)) + { + registeredCourses.remove(c); + c.increaseCapacity(); + return true; + } return false; } - public void showRegisteredCourses() { - // TODO: Print all registered courses + public void showRegisteredCourses() + { + if(registeredCourses.size() > 0) + { + System.out.println("Registered Courses : "); + for(int i = 0; i < registeredCourses.size(); i++) { + Course c = registeredCourses.get(i); + System.out.println(c.getCourseName()); + } + } + else + { + System.out.println("NO COURSES !"); + } } } \ No newline at end of file -- 2.54.0 From cd3436131d7f4a940040b2da2924b05b64d396a1 Mon Sep 17 00:00:00 2001 From: Bita Date: Mon, 20 Apr 2026 22:44:03 +0330 Subject: [PATCH 2/3] changes in class RegistrationSystem --- .../RegistrationSystem.java | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..02cb5ea 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -1,24 +1,54 @@ package CourseRegistrationStarter; import java.util.ArrayList; -public class RegistrationSystem { +public class RegistrationSystem +{ private ArrayList courses; public RegistrationSystem() { courses = new ArrayList<>(); } - public void addCourseToSystem(Course c) { - // TODO: Add the course to the system + public void addCourseToSystem(Course c) + { + courses.add(c); } - public Course findCourseByCode(String code) { - // TODO: Search for a course by course code - // Return the matching course if found, otherwise return null + public Course findCourseByCode(String code) + { + if(courses.isEmpty()) + { + System.out.println("NOTHING HAS FOUND !"); + return null; + } + else + { + for(int i = 0; i < courses.size(); i++) + { + Course c = courses.get(i); + if(code.equals(c.getCourseCode())) + { + return c; + } + } + } + System.out.println("NOTHING HAS FOUND !"); return null; } - public void showAllCourses() { - // TODO: Print all courses in the system + public void showAllCourses() + { + if(courses.isEmpty()) + { + System.out.println("NOTHING HAS FOUND !"); + } + + for(int i = 0; i < courses.size(); i++) + { + Course c = courses.get(i); + System.out.println("Course "+ (i + 1) + " : " + c.getCourseName() + + " | code : " + c.getCourseCode() + + " | cpacity : " + c.getCapacity()); + } } -} +} \ No newline at end of file -- 2.54.0 From 3195b392af752eeaa81a926929220b69327a3740 Mon Sep 17 00:00:00 2001 From: Bita Date: Mon, 20 Apr 2026 22:59:57 +0330 Subject: [PATCH 3/3] changes in class Main --- src/CourseRegistrationStarter/Main.java | 30 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 8f06373..b9164eb 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -1,14 +1,26 @@ package CourseRegistrationStarter; public class Main { - public static void main(String[] args) { - // TODO: - // 1. Create at least 3 courses - // 2. Create 1 student - // 3. Create a registration system - // 4. Add courses to the system - // 5. Register the student in some courses - // 6. Drop one course - // 7. Print the final registered course list + public static void main(String[] args) + { + Course c1 = new Course("Advanced Programming","4041",40); + Course c2 = new Course("Math","4042",50); + Course c3 = new Course("English","4043",20); + + RegistrationSystem registrationSystem = new RegistrationSystem(); + + registrationSystem.addCourseToSystem(c1); + registrationSystem.addCourseToSystem(c2); + registrationSystem.addCourseToSystem(c3); + + Student st1 = new Student("Lionel Messi","404222010"); + + st1.addCourse(c1); + st1.addCourse(c2); + st1.addCourse(c3); + + st1.dropCourse(c2); + + st1.showRegisteredCourses(); } } -- 2.54.0