Merge pull request 'WS2' (#1) from develop into main
Reviewed-on: #1 100 / 100 * 0.7 delay
This commit was merged in pull request #1.
This commit is contained in:
@@ -2,13 +2,27 @@ package CourseRegistrationStarter;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO:
|
Course c1 = new Course("Advanced Programming", "AP1404", 2);
|
||||||
// 1. Create at least 3 courses
|
Course c2 = new Course("Data Structures", "DS2201", 1);
|
||||||
// 2. Create 1 student
|
Course c3 = new Course("Database Systems", "DB3301", 3);
|
||||||
// 3. Create a registration system
|
|
||||||
// 4. Add courses to the system
|
Student student = new Student("Ali", "402222001");
|
||||||
// 5. Register the student in some courses
|
|
||||||
// 6. Drop one course
|
RegistrationSystem system = new RegistrationSystem();
|
||||||
// 7. Print the final registered course list
|
|
||||||
|
system.addCourseToSystem(c1);
|
||||||
|
system.addCourseToSystem(c2);
|
||||||
|
system.addCourseToSystem(c3);
|
||||||
|
|
||||||
|
student.addCourse(c1);
|
||||||
|
student.addCourse(c2);
|
||||||
|
|
||||||
|
student.dropCourse(c1);
|
||||||
|
|
||||||
|
System.out.println("Registered Courses:");
|
||||||
|
student.showRegisteredCourses();
|
||||||
|
|
||||||
|
System.out.println("\nAll Courses in System:");
|
||||||
|
system.showAllCourses();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 (Course c : courses) {
|
||||||
// Return the matching course if found, otherwise return null
|
if (c.getCourseCode().equals(code)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showAllCourses() {
|
public void showAllCourses() {
|
||||||
// TODO: Print all courses in the system
|
for (Course c : courses) {
|
||||||
|
System.out.println(c.getCourseName() + " - " + c.getCourseCode() + " - Remaining Capacity: " + c.getCapacity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,19 +21,26 @@ 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) && c.getCapacity() > 0) {
|
||||||
// Return true if registration was successful, otherwise false
|
if (c.reduceCapacity()) {
|
||||||
|
registeredCourses.add(c);
|
||||||
|
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
|
if (registeredCourses.remove(c)) {
|
||||||
// Restore the course capacity if removal was successful
|
c.increaseCapacity();
|
||||||
// Return true if the course was dropped, otherwise false
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRegisteredCourses() {
|
public void showRegisteredCourses() {
|
||||||
// TODO: Print all registered courses
|
for (Course c : registeredCourses) {
|
||||||
|
System.out.println(c.getCourseName() + " - " + c.getCourseCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user