2 Commits
Author SHA1 Message Date
ShayanEdalatjoo 1e03e35f9c Fixing reported bugs. 2026-05-23 09:48:51 +03:30
ShayanEdalatjoo 8f1cd0d721 finishing TODO parts 2026-04-20 23:15:32 +03:30
3 changed files with 44 additions and 18 deletions
+18 -8
View File
@@ -2,13 +2,23 @@ package CourseRegistrationStarter;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
// TODO: Course BP = new Course("Basic Programing", "1000", 5);
// 1. Create at least 3 courses Course AP = new Course("Advanced Programing", "1001", 5);
// 2. Create 1 student Course M = new Course("Math", "1002", 5);
// 3. Create a registration system
// 4. Add courses to the system Student shayan = new Student("Shayan", "404212345");
// 5. Register the student in some courses
// 6. Drop one course RegistrationSystem regSys = new RegistrationSystem();
// 7. Print the final registered course list regSys.addCourseToSystem(AP);
regSys.addCourseToSystem(BP);
regSys.addCourseToSystem(M);
shayan.addCourse(BP);
shayan.addCourse(AP);
shayan.addCourse(M);
shayan.dropCourse(M);
shayan.showRegisteredCourses();
} }
} }
@@ -9,16 +9,21 @@ public class RegistrationSystem {
} }
public void addCourseToSystem(Course c) { public void addCourseToSystem(Course c) {
// TODO: Add the course to the system courses.add(c);
} }
public Course findCourseByCode(String code) { public Course findCourseByCode(String code) {
// TODO: Search for a course by course code for (int i = 0; i < courses.size(); i++)
// Return the matching course if found, otherwise return null if (courses.get(i).getCourseCode().equals(code))
return courses.get(i);
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("----------------------------------------------");
}
} }
} }
+17 -6
View File
@@ -21,19 +21,30 @@ public class Student {
} }
public boolean addCourse(Course c) { public boolean addCourse(Course c) {
// TODO: Register the student in the course if capacity allows if(registeredCourses.contains(c))
// Return true if registration was successful, otherwise false return false;
if((c.getCapacity() > 0)){
this.registeredCourses.add(c);
c.reduceCapacity();
return true;
}
return false; return false;
} }
public boolean dropCourse(Course c) { public boolean dropCourse(Course c) {
// TODO: Remove the course from the student's list for(int i = 0; i < this.registeredCourses.size(); i++){
// Restore the course capacity if removal was successful if (this.registeredCourses.get(i).getCourseCode().equals(c.getCourseCode())){
// Return true if the course was dropped, otherwise false this.registeredCourses.remove(i);
c.increaseCapacity();
return true;
}
}
return false; return false;
} }
public void showRegisteredCourses() { public void showRegisteredCourses() {
// TODO: Print all registered courses for(int i = 0; i < registeredCourses.size(); i++){
System.out.println(this.registeredCourses.get(i).getCourseName() + ", code: " + this.registeredCourses.get(i).getCourseCode());
}
} }
} }