develop #2

Open
ShayanEdalatjoo wants to merge 2 commits from develop into main
3 changed files with 8 additions and 25 deletions
Showing only changes of commit 1e03e35f9c - Show all commits
-11
View File
@@ -20,16 +20,5 @@ public class Main {
shayan.dropCourse(M); shayan.dropCourse(M);
shayan.showRegisteredCourses(); shayan.showRegisteredCourses();
// 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
} }
} }
@@ -10,20 +10,20 @@ public class RegistrationSystem {
public void addCourseToSystem(Course c) { public void addCourseToSystem(Course c) {
courses.add(c); courses.add(c);
// TODO: Add the course to the system
} }
public Course findCourseByCode(String code) { public Course findCourseByCode(String code) {
for(int i = 0; i < courses.size(); i++){ for (int i = 0; i < courses.size(); i++)
if (courses.get(i).getCourseCode().equals(code)) if (courses.get(i).getCourseCode().equals(code))
return courses.get(i); return courses.get(i);
}
// TODO: Search for a course by course code
// Return the matching course if found, otherwise return null
return null; return null;
} }
public void showAllCourses() { public void showAllCourses() {
// TODO: Print all courses in the system for (Course course : this.courses) {
System.out.println("----------------------------------------------");
System.out.printf("Course Name: %s| Course ID: %s | Capacity %d\n", course.getCourseName(), course.getCourseCode(), course.getCapacity());
System.out.println("----------------------------------------------");
}
} }
} }
+2 -8
View File
@@ -28,22 +28,17 @@ public class Student {
c.reduceCapacity(); c.reduceCapacity();
return true; return true;
} }
// TODO: Register the student in the course if capacity allows
// Return true if registration was successful, otherwise false
return false; return false;
} }
public boolean dropCourse(Course c) { public boolean dropCourse(Course c) {
for(int i = 0; i < this.registeredCourses.size(); i++){ for(int i = 0; i < this.registeredCourses.size(); i++){
if (this.registeredCourses.get(i) == c){ if (this.registeredCourses.get(i).getCourseCode().equals(c.getCourseCode())){
this.registeredCourses.remove(c); this.registeredCourses.remove(i);
c.increaseCapacity(); c.increaseCapacity();
return true; return true;
} }
} }
// 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; return false;
} }
@@ -51,6 +46,5 @@ public class Student {
for(int i = 0; i < registeredCourses.size(); i++){ for(int i = 0; i < registeredCourses.size(); i++){
System.out.println(this.registeredCourses.get(i).getCourseName() + ", code: " + this.registeredCourses.get(i).getCourseCode()); System.out.println(this.registeredCourses.get(i).getCourseName() + ", code: " + this.registeredCourses.get(i).getCourseCode());
} }
// TODO: Print all registered courses
} }
} }