Browse Source

Adjusted the implementation of Cases 6-9 from the new menu to the older ones

remotes/origin/fdai7887
fdai7600 11 months ago
parent
commit
b6948da1eb
  1. 64
      src/main/java/org/example/Administration.java
  2. 17
      src/main/java/org/example/Main.java
  3. 4
      src/main/java/org/example/Student.java

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

@ -407,6 +407,70 @@ public class Administration {
} }
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;
}
}
public void viewCourses() {
if (courses.isEmpty()) {
System.out.println("No courses available.");
} else {
System.out.println("Available Courses:");
for (Course course : courses) {
course.printCourseInfo();
}
}
}
public boolean assignGradeToStudent(String studentId, String courseId, String grade) {
Student student = findStudentById(studentId);
// First, find the course by ID to ensure it exists in the system.
Course course = findCourseByID(courseId);
if (student != null && course != null) {
// Check if the student is enrolled in the specified course.
if (student.getCourseGrades().containsKey(course)) {
// Student is enrolled in the course, proceed to assign the grade.
student.getCourseGrades().put(course, grade);
return true;
} else {
// Student is not enrolled in the specified course.
System.out.println("Student is not enrolled in the specified course.");
return false;
}
}
return false;
}
} }

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

@ -58,10 +58,23 @@ public class Main {
// Delete Course // Delete Course
break; break;
case 8: case 8:
// View Courses
administration.viewCourses();
break; break;
case 9:
case 9:{
// Assign Grade to Student // Assign Grade to Student
System.out.println("Assign Grade to Student selected");
System.out.print("Enter Student ID: ");
String toBeGradedStudentId = scanner.next();
System.out.print("Enter Course ID: ");
String toBeGradedCourseId = scanner.next();
System.out.print("Enter Grade: ");
String grade = scanner.next();
boolean success = administration.assignGradeToStudent(toBeGradedStudentId, toBeGradedCourseId, grade);
if (success) {
System.out.println("Grade assigned successfully.");
} else {
System.out.println("Failed to assign grade. Ensure the student and course IDs are correct.");
}}
break; break;
case 10: case 10:
// View Grades from Student // View Grades from Student

4
src/main/java/org/example/Student.java

@ -107,6 +107,10 @@ public class Student {
return students; return students;
} }
public void assignGrade(Course course, String grade) {
this.courseGrades.put(course, grade);
}
} }
Loading…
Cancel
Save