diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 5e7f8e1..dd214cc 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -1,6 +1,9 @@ package org.example; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Scanner; public class Administration { /** @@ -405,38 +408,6 @@ 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 enrollProfInCourse(){ System.out.println("Please enter Professor ID"); @@ -507,24 +478,35 @@ public class Administration { } - public boolean assignGradeToStudent(String studentId, String courseId, String grade) { + 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); - // 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); + // 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 { - // Student is not enrolled in the specified course. - System.out.println("Student is not enrolled in the specified course."); + 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; } - return false; } public void viewCourses() { @@ -538,6 +520,27 @@ public class Administration { } } + + 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; + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index aa3cdb0..0bc5252 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -80,36 +80,26 @@ public class Main { } break; case 8: - // View Courses administration.viewCourses(); break; - case 9: + case 9:{ // Assign Grade to Student System.out.println("Assign Grade to Student selected"); System.out.print("Enter Student ID: "); - String toBeGradedstudentId = scanner.next(); + String toBeGradedStudentId = scanner.next(); System.out.print("Enter Course ID: "); - String toBeGradedcourseId = scanner.next(); + String toBeGradedCourseId = scanner.next(); System.out.print("Enter Grade: "); String grade = scanner.next(); - - boolean success = administration.assignGradeToStudent(toBeGradedstudentId, toBeGradedcourseId, grade); + 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; case 10: // View Grades from Student - System.out.print("Enter Student ID to view grades: "); - String GradedstudentId = scanner.next(); - Student student = administration.findStudentById(GradedstudentId); - if (student != null) { - student.printGrades(); - } else { - System.out.println("Student not found."); - } break; case 11: diff --git a/src/main/java/org/example/Student.java b/src/main/java/org/example/Student.java index 2d510ff..8cfe740 100644 --- a/src/main/java/org/example/Student.java +++ b/src/main/java/org/example/Student.java @@ -108,15 +108,9 @@ public class Student { } public void assignGrade(Course course, String grade) { - // Assuming courseGrades is a Map where the course is the key and the grade is the value this.courseGrades.put(course, grade); } - public void printGrades() { - System.out.println("Grades for Student ID: " + this.studentId); - for (Map.Entry entry : courseGrades.entrySet()) { - System.out.println("Course: " + entry.getKey().getCourseName() + ", Grade: " + entry.getValue()); - } - } + } diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 647c024..0397e89 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -324,6 +324,33 @@ class AdministrationTest { } + + @Test + void dropProfFromCourse(){ + Professor prof = sampleProf; + Course course = sampleCourse; + List courseList = prof.getCoursesTaught(); + courseList.add(course); + prof.setCoursesTaught(courseList); + + //The "User input" to determine the professor + String profID = prof.getProfessorID(); + + //Grabs the coursesTaught List from the Professor the user wants to enroll + List courseList2 = prof.getCoursesTaught(); + //Assigning the course to the Prof by adding it the to the courseList + courseList2.remove(course); + //The Professor gets the updated courseList + prof.setCoursesTaught(courseList); + + + //Checks if the course got removed + assertEquals(0,prof.getCoursesTaught().size() ); + + } + + + @Test void registerUser() { Administration administration = new Administration();