2 Commits
Author SHA1 Message Date
MehrdadShirvani 1570d9c7ac Merge PR 'Complete Work Shop 2' (#1) from develop into main
Full Mark - No Bonus - Late Submission
2026-07-10 19:24:09 +00:00
faraz_ardeh e9370069cf Complete Work Shop 2 2026-06-16 16:24:35 +03:30
3 changed files with 41 additions and 18 deletions
+19 -8
View File
@@ -2,13 +2,24 @@ package CourseRegistrationStarter;
public class Main {
public static void main(String[] args) {
// 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
Course c1 = new Course("Introduction to Programming", "CS101", 30);
Course c2 = new Course("Data Structures", "CS201", 25);
Course c3 = new Course("Algorithms", "CS301", 20);
Student student = new Student("Alice", "S1001");
RegistrationSystem system = new RegistrationSystem();
system.addCourseToSystem(c1);
system.addCourseToSystem(c2);
system.addCourseToSystem(c3);
student.addCourse(c1);
student.addCourse(c2);
student.addCourse(c3);
student.dropCourse(c2);
System.out.println("Registered courses for " + student.getName() + ":");
student.showRegisteredCourses();
}
}
@@ -9,16 +9,21 @@ public class RegistrationSystem {
}
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
for (Course c : courses) {
if (c.getCourseCode().equals(code)) {
return c;
}
}
return null;
}
public void showAllCourses() {
// TODO: Print all courses in the system
for (Course c : courses) {
System.out.println(c.getCourseCode() + " - " + c.getCourseName() + " (Capacity: " + c.getCapacity() + ")");
}
}
}
+13 -6
View File
@@ -21,19 +21,26 @@ 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
boolean success = c.reduceCapacity();
if (success) {
registeredCourses.add(c);
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
boolean removed = registeredCourses.remove(c);
if (removed) {
c.increaseCapacity();
return true;
}
return false;
}
public void showRegisteredCourses() {
// TODO: Print all registered courses
for (Course c : registeredCourses) {
System.out.println(c.getCourseCode() + " - " + c.getCourseName());
}
}
}