changes in class RegistrationSystem

This commit is contained in:
2026-04-20 22:44:03 +03:30
parent e8bafc4140
commit cd3436131d
@@ -1,24 +1,54 @@
package CourseRegistrationStarter;
import java.util.ArrayList;
public class RegistrationSystem {
public class RegistrationSystem
{
private ArrayList<Course> courses;
public RegistrationSystem() {
courses = new ArrayList<>();
}
public void addCourseToSystem(Course c) {
// TODO: Add the course to the system
public void addCourseToSystem(Course c)
{
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
public Course findCourseByCode(String code)
{
if(courses.isEmpty())
{
System.out.println("NOTHING HAS FOUND !");
return null;
}
else
{
for(int i = 0; i < courses.size(); i++)
{
Course c = courses.get(i);
if(code.equals(c.getCourseCode()))
{
return c;
}
}
}
System.out.println("NOTHING HAS FOUND !");
return null;
}
public void showAllCourses() {
// TODO: Print all courses in the system
public void showAllCourses()
{
if(courses.isEmpty())
{
System.out.println("NOTHING HAS FOUND !");
}
for(int i = 0; i < courses.size(); i++)
{
Course c = courses.get(i);
System.out.println("Course "+ (i + 1) + " : " + c.getCourseName()
+ " | code : " + c.getCourseCode()
+ " | cpacity : " + c.getCapacity());
}
}
}
}