From 7b2d0dafb751919af869ad0f9370b40ccdf6bec2 Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 21:52:37 +0100 Subject: [PATCH] refactoring: Moved dropStudentFromCourse Method to Administration class --- src/main/java/org/example/Administration.java | 28 ++++++++++++++++--- src/main/java/org/example/Main.java | 21 +------------- 2 files changed, 25 insertions(+), 24 deletions(-) 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: