diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index dd214cc..3613768 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -1,9 +1,6 @@ package org.example; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Scanner; +import java.util.*; public class Administration { /** @@ -541,6 +538,29 @@ public class Administration { return false; } + public void dropStudentFromCourse(String studentID, String courseID){ + Student student = this.findStudentById(studentID); + Course course = this.findCourseByID(courseID); + + Map studentCourses = student.getCourseGrades(); + if (student != null && course != null) { + + if(studentCourses.containsKey(course)){ + studentCourses.remove(course); + student.setCourseGrades(studentCourses); + System.out.println("Student has been dropped from the choosen course"); + } + else{ + System.out.println("Student was not in this course"); + } + + } else { + if (student == null) System.out.println("Student ID not found."); + if (course == null) System.out.println("Course ID not found."); + } + + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 728bf80..a3b0321 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -63,26 +63,7 @@ public class Main { System.out.println("Enter Course ID"); String courseIdToDrop = scanner.next(); - Student student = administration.findStudentById(studentID); - Course course = administration.findCourseByID(courseIdToDrop); - - Map studentCourses = student.getCourseGrades(); - if (student != null && course != null) { - - if(studentCourses.containsKey(course)){ - studentCourses.remove(course); - student.setCourseGrades(studentCourses); - System.out.println("Student has been dropped from the choosen course"); - } - else{ - System.out.println("Student was not in this course"); - } - - } else { - if (student == null) System.out.println("Student ID not found."); - if (course == null) System.out.println("Course ID not found."); - } - + administration.dropStudentFromCourse(studentID, courseIdToDrop); break; case 6: