Completed the Registration System (With Bonus).

This commit is contained in:
2026-04-20 20:46:38 +03:30
parent 8ddd529c85
commit 747406a5aa
3 changed files with 36 additions and 7 deletions
Generated
+1
View File
@@ -0,0 +1 @@
Student.java
@@ -1,5 +1,6 @@
package CourseRegistrationStarter; package CourseRegistrationStarter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner;
public class RegistrationSystem { public class RegistrationSystem {
private ArrayList<Course> courses; private ArrayList<Course> courses;
@@ -9,16 +10,44 @@ public class RegistrationSystem {
} }
public void addCourseToSystem(Course c) { public void addCourseToSystem(Course c) {
// TODO: Add the course to the system Scanner scanner = new Scanner(System.in);
String courseName = scanner.next();
String courseCode = scanner.next();
int capacity = scanner.nextInt();
Course newCourse = new Course(courseName, courseCode, capacity);
courses.add(newCourse);
} }
public Course findCourseByCode(String code) { public Course findCourseByCode(String code) {
// TODO: Search for a course by course code for (Course i : courses)
// Return the matching course if found, otherwise return null {
if (i.getCourseCode().equals(code))
{
return i;
}
}
return null;
}
public Course findCourseByName(String name) {
for (Course i : courses)
{
if (i.getCourseCode().equals(name))
{
return i;
}
}
return null; return null;
} }
public void showAllCourses() { public void showAllCourses() {
// TODO: Print all courses in the system for (Course i : courses)
{
System.out.println(i.getCourseName());
System.out.println(i.getCourseCode());
System.out.println(i.getCapacity());
}
} }
} }
+1 -2
View File
@@ -21,8 +21,7 @@ public class Student {
} }
public boolean addCourse(Course c) { public boolean addCourse(Course c) {
// TODO: Register the student in the course if capacity allows
// Return true if registration was successful, otherwise false
return false; return false;
} }