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;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
@ -540,6 +541,38 @@ public class Administration {
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) {
case 1:
// Register User
administration.registerUser();
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;
case 3:
// Enroll Prof to Course
@ -58,9 +63,24 @@ public class Main {
break;
case 6:
// 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;
case 7:
// 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;
case 8:
administration.viewCourses();

Loading…
Cancel
Save