Complete all classes .

This commit is contained in:
2026-04-22 08:24:36 +03:30
parent 8ddd529c85
commit 7799199b08
4 changed files with 57 additions and 0 deletions
Generated
+1
View File
@@ -0,0 +1 @@
Course.java
+25
View File
@@ -4,11 +4,36 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
// TODO: // TODO:
// 1. Create at least 3 courses // 1. Create at least 3 courses
Course course1 = new Course("Advanced Programming" , "AP1404", 2) ;
Course course2 = new Course("Data Structures", "DS2201", 1) ;
Course course3 = new Course("Database Systems", "DB3301", 3) ;
// 2. Create 1 student // 2. Create 1 student
Student student1 = new Student ("Ali", "402222001") ;
// 3. Create a registration system // 3. Create a registration system
RegistrationSystem registrationSystem = new RegistrationSystem() ;
// 4. Add courses to the system // 4. Add courses to the system
registrationSystem.addCourseToSystem(course1) ;
registrationSystem.addCourseToSystem(course2) ;
registrationSystem.addCourseToSystem(course3) ;
// 5. Register the student in some courses // 5. Register the student in some courses
student1.addCourse(course1) ;
student1.addCourse(course2) ;
student1.addCourse(course3) ;
// 6. Drop one course // 6. Drop one course
student1.dropCourse(course2) ;
// 7. Print the final registered course list // 7. Print the final registered course list
student1.showRegisteredCourses() ;
registrationSystem.showAllCourses();
} }
} }
@@ -10,15 +10,27 @@ public class RegistrationSystem {
public void addCourseToSystem(Course c) { public void addCourseToSystem(Course c) {
// TODO: Add the course to the system // 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 // TODO: Search for a course by course code
for (int i = 0 ; i < courses.size() ; i++)
{
if ( courses.get(i).getCourseCode().equals(code))
{
return courses.get(i);
}
}
// Return the matching course if found, otherwise return null // 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 // TODO: Print all courses in the system
for (int i = 0 ; i < courses.size() ; i++)
{
System.out.println(courses.get(i).getCourseName() + " (" + courses.get(i).getCourseCode() + ") - Remaining Capacity: " + courses.get(i).getCapacity());
}
} }
} }
@@ -22,12 +22,26 @@ public class Student {
public boolean addCourse(Course c) { public boolean addCourse(Course c) {
// TODO: Register the student in the course if capacity allows // TODO: Register the student in the course if capacity allows
if (c.getCapacity() > 0)
{
registeredCourses.add(c) ;
c.reduceCapacity() ;
return true ;
}
// Return true if registration was successful, otherwise false // Return true if registration was successful, otherwise false
return false; return false;
} }
public boolean dropCourse(Course c) { public boolean dropCourse(Course c) {
// TODO: Remove the course from the student's list // TODO: Remove the course from the student's list
if (registeredCourses.remove(c))
{
c.increaseCapacity() ;
return true ;
}
// Restore the course capacity if removal was successful // Restore the course capacity if removal was successful
// Return true if the course was dropped, otherwise false // Return true if the course was dropped, otherwise false
return false; return false;
@@ -35,5 +49,10 @@ public class Student {
public void showRegisteredCourses() { public void showRegisteredCourses() {
// TODO: Print all registered courses // TODO: Print all registered courses
for(int i = 0 ; i < registeredCourses.size() ; i++)
{
System.out.println(registeredCourses.get(i).getCourseName() + " - " + registeredCourses.get(i).getCourseCode());
}
} }
} }