Browse Source

Merge remote-tracking branch 'origin/fdai7600'

# Conflicts:
#	src/main/java/org/example/Administration.java
remotes/origin/fdai7887
fdai7600 11 months ago
parent
commit
a6c886ac1e
  1. 33
      src/main/java/org/example/Administration.java
  2. 24
      src/main/java/org/example/Main.java

33
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;
@ -540,6 +541,38 @@ public class Administration {
return false; return false;
} }
public void createCourse(String courseName, String courseID, int credits) {
// Check if a course with the given ID already exists
if (findCourseByID(courseID) != null) {
System.out.println("A course with ID " + courseID + " already exists.");
} else {
Course newCourse = new Course(courseName, courseID, credits);
courses.add(newCourse);
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;
}
}
} }

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

@ -40,9 +40,14 @@ public class Main {
switch (choice) { switch (choice) {
case 1: case 1:
// Register User // Register User
administration.registerUser();
break; break;
case 2:
// Enroll Student in Course
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; break;
case 3: case 3:
// Enroll Prof to Course // Enroll Prof to Course
@ -58,9 +63,24 @@ public class Main {
break; break;
case 6: case 6:
// Create Course // Create Course
System.out.println("Enter Course Name:");
String courseName = scanner.next();
System.out.println("Enter Course ID:");
String courseID = scanner.next();
System.out.println("Enter Credits:");
int credits = scanner.nextInt();
administration.createCourse(courseName, courseID, credits);
break; break;
case 7: case 7:
// Delete Course // Delete Course
System.out.println("Enter the Course ID of the course you wish to delete:");
String courseIDToDelete = scanner.next();
boolean isDeleted = administration.deleteCourse(courseIDToDelete);
if (isDeleted) {
System.out.println("Course with ID " + courseIDToDelete + " has been successfully deleted.");
} else {
System.out.println("Course with ID " + courseIDToDelete + " not found.");
}
break; break;
case 8: case 8:
administration.viewCourses(); administration.viewCourses();

Loading…
Cancel
Save