diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index 2228164..06d7547 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -7,7 +7,7 @@ public class Main { Course DataStructures = new Course("DataStructures", "DS2201", 1); Course DatabaseSystems = new Course("DatabaseSystems", "DB3301", 3); - Student fateme = new Student("fateme", "404222000"); + Student fateme = new Student("fateme", "404222000", 10); RegistrationSystem A = new RegistrationSystem(); diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index ba9f0c0..09acb07 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -12,7 +12,10 @@ public class RegistrationSystem { for (int i=0 ; i < courses.size() ; i++) { - if(courses.get(i).getCourseCode().equals(c.getCourseCode())) { + if(courses.get(i).getCourseCode().equals(c.getCourseCode()) || + courses.get(i).getCourseName().equals(c.getCourseName())) { + + System.out.println("Course name or code already exists."); return; } } @@ -31,6 +34,15 @@ public class RegistrationSystem { return null; } + public Course findCourseByName(String name) { + + for(int i=0 ; i registeredCourses; + private int courseLimit; - public Student(String name, String studentId) { + public Student(String name, String studentId, int courseLimit) { this.name = name; this.studentId = studentId; this.registeredCourses = new ArrayList<>(); + this.courseLimit = courseLimit; } public String getName() { @@ -22,7 +24,7 @@ public class Student { public boolean addCourse(Course c) { - if(c.getCapacity() > 0) { + if(c.getCapacity() > 0 && registeredCourses.size() < courseLimit) { registeredCourses.add(c); c.reduceCapacity(); return true; @@ -30,6 +32,11 @@ public class Student { return false; } + public void setCourseLimit(int amount) { + if(amount>0) + courseLimit = amount; + } + public boolean dropCourse(Course c) { if (registeredCourses.remove(c)) { c.increaseCapacity();