35 lines
1.0 KiB
Java
35 lines
1.0 KiB
Java
package CourseRegistrationStarter;
|
|
import java.util.ArrayList;
|
|
|
|
public class RegistrationSystem {
|
|
private ArrayList<Course> courses;
|
|
|
|
public RegistrationSystem() {
|
|
courses = new ArrayList<>();
|
|
}
|
|
|
|
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 thisCourse : courses){
|
|
if(thisCourse.getCourseCode() == code){
|
|
return thisCourse;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void showAllCourses() {
|
|
// TODO: Print all courses in the system
|
|
System.out.println("Course Name | Course Code | Capacity");
|
|
for(Course thisCourse : courses){
|
|
System.out.printf("%s | %s | %d\n", thisCourse.getCourseName(), thisCourse.getCourseCode(), thisCourse.getCapacity());
|
|
}
|
|
}
|
|
}
|