Complete assignment #1

Merged
peyman merged 4 commits from develop into main 2026-04-25 21:47:48 +00:00
3 changed files with 16 additions and 2 deletions
Showing only changes of commit 193137771e - Show all commits
+1 -1
View File
@@ -27,7 +27,7 @@ public class Main {
student1.dropCourse(course2); student1.dropCourse(course2);
// 7. Print the final registered course list // 7. Print the final registered course list
System.out.printf("%s registered courses:\n", student1.getName()); System.out.printf("\n%s\'s registered courses:\n", student1.getName());
student1.showRegisteredCourses(); student1.showRegisteredCourses();
System.out.println("\nRemaining informations of courses are as follows: "); System.out.println("\nRemaining informations of courses are as follows: ");
@@ -24,6 +24,15 @@ public class RegistrationSystem {
return null; return null;
} }
public Course findCourseByName(String name){ // search by course name
for(Course thisCourse : courses){
if(thisCourse.getCourseName() == name){
return thisCourse;
}
}
return null;
}
public void showAllCourses() { public void showAllCourses() {
// TODO: Print all courses in the system // TODO: Print all courses in the system
System.out.println("Course Name | Course Code | Capacity"); System.out.println("Course Name | Course Code | Capacity");
+6 -1
View File
@@ -5,6 +5,7 @@ public class Student {
private String name; private String name;
private String studentId; private String studentId;
private ArrayList<Course> registeredCourses; private ArrayList<Course> registeredCourses;
private int allowedCourses = 2;
public Student(String name, String studentId) { public Student(String name, String studentId) {
this.name = name; this.name = name;
@@ -24,11 +25,15 @@ public class Student {
// TODO: Register the student in the course if capacity allows // TODO: Register the student in the course if capacity allows
// Return true if registration was successful, otherwise false // Return true if registration was successful, otherwise false
if(registeredCourses.contains(c)){ if(registeredCourses.contains(c)){ // Preventing duplicate course registration
System.out.printf("%s is already registered for %s\n", c.getCourseName(), name); System.out.printf("%s is already registered for %s\n", c.getCourseName(), name);
return false; return false;
} }
if(registeredCourses.size() >= allowedCourses){ // Limiting the number of courses per student
System.out.printf("%s has reached his limit for registration.\n", name);
}
if(c.reduceCapacity()){ // if enough capacity, reduction happens in this line if(c.reduceCapacity()){ // if enough capacity, reduction happens in this line
registeredCourses.add(c); registeredCourses.add(c);
System.out.printf("%s registered successfully.\n", c.getCourseName()); System.out.printf("%s registered successfully.\n", c.getCourseName());