Browse Source

refactoring: Moved dropStudentFromCourse Method to Administration class

remotes/origin/fdai7887
fdai7887 11 months ago
parent
commit
7b2d0dafb7
  1. 28
      src/main/java/org/example/Administration.java
  2. 21
      src/main/java/org/example/Main.java

28
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<Course, String> 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.");
}
}
}

21
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<Course, String> 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:

Loading…
Cancel
Save