5 Commits
3 changed files with 59 additions and 18 deletions
+20 -8
View File
@@ -2,13 +2,25 @@ 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 AdvancedProgramming = new Course("AdvancedProgramming", "AP1404", 2);
Course DataStructures = new Course("DataStructures", "DS2201", 1);
Course DatabaseSystems = new Course("DatabaseSystems", "DB3301", 3);
Student fateme = new Student("fateme", "404222000");
RegistrationSystem A = new RegistrationSystem();
A.addCourseToSystem(AdvancedProgramming);
A.addCourseToSystem(DataStructures);
A.addCourseToSystem(DatabaseSystems);
fateme.addCourse(AdvancedProgramming);
fateme.addCourse(DataStructures);
fateme.addCourse(DatabaseSystems);
fateme.dropCourse(DataStructures);
fateme.showRegisteredCourses();
}
}
@@ -9,16 +9,34 @@ public class RegistrationSystem {
}
public void addCourseToSystem(Course c) {
// TODO: Add the course to the system
for (int i=0 ; i < courses.size() ; i++) {
if(courses.get(i).getCourseCode().equals(c.getCourseCode())) {
return;
}
}
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(int i=0 ; i < courses.size() ; i++) {
if(courses.get(i).getCourseCode().equals(code)) {
return courses.get(i);
}
}
return null;
}
public void showAllCourses() {
// TODO: Print all courses in the system
for(int i=0 ; i < courses.size() ; i++) {
System.out.print("Course");
System.out.print(i+1);
System.out.print(" : " + courses.get(i).getCourseName() + " " + courses.get(i).getCourseCode());
System.out.println(", capacity : " + courses.get(i).getCapacity());
}
}
}
+17 -6
View File
@@ -21,19 +21,30 @@ 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
if(c.getCapacity() > 0) {
registeredCourses.add(c);
c.reduceCapacity();
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
if (registeredCourses.remove(c)) {
c.increaseCapacity();
return true;
}
return false;
}
public void showRegisteredCourses() {
// TODO: Print all registered courses
for(int i=0 ; i < registeredCourses.size() ; i++) {
System.out.print("Course");
System.out.print(i+1);
System.out.print(" : " + registeredCourses.get(i).getCourseName() + " " + registeredCourses.get(i).getCourseCode());
System.out.println(", capacity : " +registeredCourses.get(i).getCapacity());
}
}
}