Browse Source

Added the new Enroll Student in course

remotes/origin/fdai7780
fdai7600 11 months ago
parent
commit
c96fbd2d52
  1. 22
      src/main/java/org/example/Administration.java
  2. 9
      src/main/java/org/example/Main.java

22
src/main/java/org/example/Administration.java

@ -1,6 +1,7 @@
package org.example; package org.example;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
@ -418,6 +419,27 @@ public class Administration {
System.out.println("Course " + courseName + " (" + courseID + ") created successfully."); System.out.println("Course " + courseName + " (" + courseID + ") created successfully.");
} }
} }
public boolean enrollStudentInCourse(String studentId, String courseId) {
Student student = findStudentById(studentId);
Course course = findCourseByID(courseId);
if (student != null && course != null) {
// If the course is not already enrolled
if (!student.getCourseGrades().containsKey(course)) {
student.getCourseGrades().put(course, "Not Graded");
System.out.println("Student " + studentId + " enrolled in course " + courseId + ".");
return true;
} else {
System.out.println("Student " + studentId + " is already enrolled in course " + courseId + ".");
return false;
}
} else {
if (student == null) System.out.println("Student ID not found.");
if (course == null) System.out.println("Course ID not found.");
return false;
}
}
} }

9
src/main/java/org/example/Main.java

@ -40,8 +40,13 @@ public class Main {
// Register User // Register User
administration.registerUser(); administration.registerUser();
break; break;
case 2:
break;
case 2: // Enroll Student in Course
System.out.println("Enter Student ID:");
String studentId = scanner.next();
System.out.println("Enter Course ID:");
String courseId = scanner.next();
administration.enrollStudentInCourse(studentId, courseId);
break;
case 3: case 3:
// Enroll Prof to Course // Enroll Prof to Course
break; break;

Loading…
Cancel
Save