From ca498f1f28838c53e5df693247db01db3e6f2b1f Mon Sep 17 00:00:00 2001 From: Matin Date: Mon, 20 Apr 2026 19:32:41 +0430 Subject: [PATCH 1/4] matin mortazavi / i did my Assignment + bonus --- src/CourseRegistrationStarter/Main.java | 15 ++++++ .../RegistrationSystem.java | 47 +++++++++++++++++++ src/CourseRegistrationStarter/Student.java | 33 ++++++++++++- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 8f06373..a9b307e 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -10,5 +10,20 @@ public class Main { // 5. Register the student in some courses // 6. Drop one course // 7. Print the final registered course list + RegistrationSystem reg = new RegistrationSystem() ; + Course Ap = new Course("ap" , "1404" , 2 ); + reg.addCourseToSystem(Ap) ; + Course DS = new Course("DS" , "2201" , 1 ); + reg.addCourseToSystem(DS); + Course DB = new Course("Db" , "3301" , 3 ); + reg.addCourseToSystem(DB); + Student Ali = new Student("ali" , "402222001") ; + Ali.addCourse(Ap) ; + Ali.addCourse(DB) ; + Ali.dropCourse(Ap) ; + Ali.showRegisteredCourses(); + reg.showcapacity(); + + } } diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..72f34f8 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -1,5 +1,6 @@ package CourseRegistrationStarter; import java.util.ArrayList; +import java.util.Objects; public class RegistrationSystem { private ArrayList courses; @@ -10,15 +11,61 @@ public class RegistrationSystem { public void addCourseToSystem(Course c) { // TODO: Add the course to the system + if (courses.contains(c)) { + System.out.println("you cant add this course !!"); + } + else + { + 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 + for (Course item : courses) + { + if (Objects.equals(item.getCourseCode(), code)) { + + return item ; + } + + } + return null; + + } + public Course findCourseByName(String name) + { + for (Course item : courses) + { + if (Objects.equals(item.getCourseCode(), name)) { + + return item ; + } + + } return null; } public void showAllCourses() { // TODO: Print all courses in the system + for (Course item : courses) + { + System.out.print("course name : "); + System.out.print(item.getCourseName()); + System.out.print(" , course code"); + System.out.print(item.getCourseCode()); + System.out.print(" , course capacity"); + System.out.print(item.getCapacity()); + + } + } + public void showcapacity(){ + for (Course item : courses) + { + System.out.println(item.getCapacity()); + } } } diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..b4d0177 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -23,17 +23,46 @@ 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; + if (registeredCourses.size()<= 10) { + if (c.reduceCapacity()) { + registeredCourses.add(c); + return true; + } else { + + return false; + } + } + else + { + 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 - return false; + int ind = registeredCourses.indexOf(c) ; + if (ind != -1 ) + { + registeredCourses.remove(ind) ; + c.increaseCapacity(); + return true ; + } + else { + return false; + } } public void showRegisteredCourses() { // TODO: Print all registered courses + for (Course item : registeredCourses) + { + System.out.print("course name : "); + System.out.print(item.getCourseName()); + System.out.print(" , course code"); + System.out.print(item.getCourseCode()); + + } } } \ No newline at end of file From 8e69c031e1b35f009bdb5705406b1be3de7cf10b Mon Sep 17 00:00:00 2001 From: Matin Date: Mon, 20 Apr 2026 21:34:24 +0430 Subject: [PATCH 2/4] matin mortazavi / work shop + bonus --- src/CourseRegistrationStarter/Course.java | 2 +- src/CourseRegistrationStarter/Main.java | 1 + src/CourseRegistrationStarter/RegistrationSystem.java | 1 + src/CourseRegistrationStarter/Student.java | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CourseRegistrationStarter/Course.java b/src/CourseRegistrationStarter/Course.java index 7f13a14..9b750f0 100644 --- a/src/CourseRegistrationStarter/Course.java +++ b/src/CourseRegistrationStarter/Course.java @@ -10,7 +10,7 @@ public class Course { this.courseCode = courseCode; this.capacity = capacity; } - + // test public String getCourseName() { return courseName; } diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index a9b307e..e686487 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -23,6 +23,7 @@ public class Main { Ali.dropCourse(Ap) ; Ali.showRegisteredCourses(); reg.showcapacity(); + //test } diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 72f34f8..2edecce 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -20,6 +20,7 @@ public class RegistrationSystem { } } + // test public Course findCourseByCode(String code) { diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index b4d0177..6f7f57d 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -35,6 +35,7 @@ public class Student { else { return false ; + // test } } From 8ddc581f611575bd30777f0175d961987869e555 Mon Sep 17 00:00:00 2001 From: Matin Date: Thu, 30 Apr 2026 02:19:31 +0430 Subject: [PATCH 3/4] add menu --- src/CourseRegistrationStarter/Main.java | 80 ++++++++++++++++--- .../RegistrationSystem.java | 1 + src/CourseRegistrationStarter/Student.java | 2 +- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index e686487..f64b798 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -1,7 +1,13 @@ package CourseRegistrationStarter; +import java.lang.reflect.Field ; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws NoSuchFieldException { // TODO: // 1. Create at least 3 courses // 2. Create 1 student @@ -11,20 +17,76 @@ public class Main { // 6. Drop one course // 7. Print the final registered course list RegistrationSystem reg = new RegistrationSystem() ; - Course Ap = new Course("ap" , "1404" , 2 ); - reg.addCourseToSystem(Ap) ; + Course AP = new Course("ap" , "1404" , 2 ); + reg.addCourseToSystem(AP) ; Course DS = new Course("DS" , "2201" , 1 ); reg.addCourseToSystem(DS); Course DB = new Course("Db" , "3301" , 3 ); reg.addCourseToSystem(DB); + Map courseMap = new HashMap<>(); + courseMap.put("AP", AP); + courseMap.put("DS", DS); + courseMap.put("DB", DB); Student Ali = new Student("ali" , "402222001") ; - Ali.addCourse(Ap) ; - Ali.addCourse(DB) ; - Ali.dropCourse(Ap) ; - Ali.showRegisteredCourses(); - reg.showcapacity(); + //test + Scanner input = new Scanner(System.in) ; + + int x = 0 ; + while (x != 6 ) { + System.out.println("menu"); + System.out.println("1) Add course "); + System.out.println("2) drop course "); + System.out.println("3) show registered courses"); + System.out.println("4 ) show all courses"); + System.out.println("5) Show capacities "); + System.out.println("6) exit "); + System.out.println("enter your choice "); + x = input.nextInt() ; + input.nextLine() ; + if (x == 1 ) + { + System.out.println("Available courses: AP - DS - DB"); + String y = input.nextLine().trim(); + Course selected = courseMap.get(y.toUpperCase()); + if (selected != null) { + Ali.addCourse(selected); + } else { + System.out.println("No"); + } + + } + + else if (x == 2 ) { + System.out.println("courses names : AP - DS - DB"); + String y = input.nextLine().trim(); + Course selected = courseMap.get(y.toUpperCase()); + if (selected != null) { + Ali.addCourse(selected); + } else { + System.out.println("No"); + } + + } + else if (x == 3 ) { + Ali.showRegisteredCourses(); + + } + else if (x == 4 ) + { + reg.showAllCourses(); + } else if (x == 5 ) { + reg.showcapacity(); + + } else if (x == 6) { + continue; + + } + + } + } + } -} + diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 2edecce..48cd8a9 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -66,6 +66,7 @@ public class RegistrationSystem { public void showcapacity(){ for (Course item : courses) { + System.out.println(item.getCapacity()); } } diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 6f7f57d..0cf7b21 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -35,7 +35,7 @@ public class Student { else { return false ; - // test + // test } } From f3b3c4268870fc75abec0d47d7c0700f25f1a821 Mon Sep 17 00:00:00 2001 From: Matin Date: Fri, 1 May 2026 01:14:29 +0430 Subject: [PATCH 4/4] finial --- src/CourseRegistrationStarter/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index f64b798..8dd65de 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -62,7 +62,7 @@ public class Main { String y = input.nextLine().trim(); Course selected = courseMap.get(y.toUpperCase()); if (selected != null) { - Ali.addCourse(selected); + Ali.dropCourse(selected); } else { System.out.println("No"); }