From 5ecf78a5456a0991bb0fc0baf4220468d0d30b3a Mon Sep 17 00:00:00 2001 From: Mahdi HP Date: Mon, 27 Apr 2026 01:57:33 -0700 Subject: [PATCH] complet classes and write tese class --- src/CourseRegistrationStarter/Main.java | 27 +++++++++++++++++++ .../RegistrationSystem.java | 24 +++++++++++++---- src/CourseRegistrationStarter/Student.java | 26 +++++++++++++----- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 8f06373..67c89d0 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -2,6 +2,33 @@ package CourseRegistrationStarter; public class Main { public static void main(String[] args) { + + Course riazi2 = new Course("riazi2" , "200" , 5); + Course ap = new Course("ap" , "201" , 2); + Course bp = new Course("bp" , "202" , 5); + Course riazi1 = new Course("riazi1" , "203" , 7); + Course os = new Course("os" , "204" , 10); + + Student daneshjo = new Student("ali" , "11111"); + + + RegistrationSystem regis = new RegistrationSystem(); + + regis.addCourseToSystem(riazi1); + regis.addCourseToSystem(riazi2); + regis.addCourseToSystem(ap); + regis.addCourseToSystem(bp); + regis.addCourseToSystem(os); + + daneshjo.addCourse(os); + daneshjo.addCourse(bp); + daneshjo.addCourse(riazi1); + + daneshjo.dropCourse(os); + + daneshjo.showRegisteredCourses(); + + regis.showAllCourses(); // TODO: // 1. Create at least 3 courses // 2. Create 1 student diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 934f222..0b4a3fd 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -5,20 +5,34 @@ public class RegistrationSystem { private ArrayList courses; public RegistrationSystem() { - courses = new ArrayList<>(); + courses = new ArrayList(); } public void addCourseToSystem(Course c) { - // TODO: Add the course to the system + 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 + int n = courses.size(); + for(int i = 0 ; i < n ; i++){ + if(courses.get(i).getCourseCode() == code){ + return courses.get(i); + } + + } return null; } public void showAllCourses() { - // TODO: Print all courses in the system + int n = courses.size(); + System.out.println("All courses :"); + for(int i = 0 ; i < n ; i++){ + + System.out.printf("course name: %10s " , courses.get(i).getCourseName()); + System.out.printf("cours capacity: %10s " , courses.get(i).getCapacity()); + System.out.println(""); + + + } } } diff --git a/src/CourseRegistrationStarter/Student.java b/src/CourseRegistrationStarter/Student.java index 02c11d8..7257077 100644 --- a/src/CourseRegistrationStarter/Student.java +++ b/src/CourseRegistrationStarter/Student.java @@ -21,19 +21,33 @@ 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 + if(c.getCapacity() > 0){ + registeredCourses.add(c); + c.reduceCapacity(); + 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 + int n = registeredCourses.size(); + for(int i = 0 ; i < n ; i++){ + if(registeredCourses.get(i).getCourseName() == c.getCourseName()){ + registeredCourses.remove(i); + c.increaseCapacity(); + return true; + } + } return false; } public void showRegisteredCourses() { - // TODO: Print all registered courses + int n = registeredCourses.size(); + System.out.println(this.name + "\'s Courses :"); + for(int i = 0 ; i < n ; i++){ + System.out.printf("course name: %10s " , registeredCourses.get(i).getCourseName()); + System.out.printf("cours code: %10s " , registeredCourses.get(i).getCourseCode()); + System.out.println(""); + } } } \ No newline at end of file