Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You\'ve been tasked with overhauling QUT\'s enrollment management system. Comple

ID: 3735274 • Letter: Y

Question

You've been tasked with overhauling QUT's enrollment management system. Complete the EnrollementManager class. All methods and fields should be static because EnrollmentManager does not need to be instantiated as an object.

Consider the first line of the class:

A Map is used here to represent the key-value pairings between units and students (thus constituting enrollments). Here, our Map keys are of type String and our values are of type Set<String>. Therefore, we can lookup a collection of students (the value) corresponding to a particular unit (the key).

A Set is used here to represent collections of students because it has the special property of enforcing unique students (no duplicate elements) for each unit.

Notice how we use HashMap on the right-hand side of this line, but Map on the left-hand side. This is because Map is the interface, and HashMap is one of several concrete implementation of Map (like List versus ArrayList in the previous exercise).

Although Set is also an interface, we do not need to specify one of the several Set implementations here because, at this point, we are only specifying the type arguments of our HashMap object. These type arguments only specify the type of the elements contained within the collection (and not the actual object values). Thus, it is up to you which of the Set implementations you use when it comes to instantiating objects to be stored in the Map values.

Again, you should read up on the methods and properties JDK APIs for the relevant collections in this exercise, as they will handle a lot of the work for you.

Finally, upload and submit your 1 class:

EnrollmentManager

ENROLLMENTMANAGER.JAVA FILE BELOW

package coll.EnrollmentManager;

import java.util.*;

public class EnrollmentManager {

private static HashMap<String, Set<String>> enrollments = new HashMap<String, Set<String>>();

/**

* Enrolls a student into a unit.

*

* @param unit

* @param student

*/

public static void enroll(String unit, String student) {

}

/**

* Gets the HashMap containing the current enrollments.

*

* @return

*/

public static HashMap<String, Set<String>> getEnrollments() {

return null;

}

/**

* Removes all enrollments form the HashMap.

*/

public static void wipeEnrollments() {

}

/**

* Withdraws a student from a unit.

*

* @param unit

* @param student

*/

public static void withdrawEnrollment(String unit, String student) {

}

/**

* Withdraws a student from all units they are enrolled in.

*

* @param student

*/

public static void withdrawStudent(String student) {

}

/**

* Gets a list of all students of a particular discipline. E.g. If discipline is

* "ABC" then return a collection of all students enrolled in units that start

* with "ABC", so ABC301, ABC299, ABC741 etc. This method is non-trivial so it

* would help to first implement the helper method matchesDiscipline (below).

*

* @param discipline

* @return

*/

public static Set<String> getStudents(String discipline) {

return null;

}

}

Explanation / Answer

Please find my implementation:

import java.util.*;

public class EnrollmentManager {

   private static HashMap<String, Set<String>> enrollments = new HashMap<String, Set<String>>();

   /**

   * Enrolls a student into a unit.

   *

   * @param unit

   * @param student

   */

   public static void enroll(String unit, String student) {

       Set<String> st = null;

       if(enrollments.containsKey(unit)) {

           st = enrollments.get(unit);

       }else{

           st = new HashSet<>();

       }

       st.add(student);

       enrollments.put(unit, st);

   }

   /**

   * Gets the HashMap containing the current enrollments.

   *

   * @return

   */

   public static HashMap<String, Set<String>> getEnrollments() {

       return enrollments;

   }

   /**

   * Removes all enrollments form the HashMap.

   */

   public static void wipeEnrollments() {

       enrollments = new HashMap<>();

   }

   /**

   * Withdraws a student from a unit.

   *

   * @param unit

   * @param student

   */

   public static void withdrawEnrollment(String unit, String student) {

       if(enrollments.containsKey(unit)) {

           Set<String>   st = enrollments.get(unit);

           st.remove(student);

           enrollments.put(unit, st);

       }

   }

   /**

   * Withdraws a student from all units they are enrolled in.

   *

   * @param student

   */

   public static void withdrawStudent(String student) {

       for(Map.Entry<String, Set<String>> entry : enrollments.entrySet()) {

           if(entry.getValue().contains(student)) {

               Set<String> st = entry.getValue();

               st.remove(student);

               enrollments.put(entry.getKey(), st);

           }

       }

   }

   /**

   * Gets a list of all students of a particular discipline. E.g. If discipline is

   * "ABC" then return a collection of all students enrolled in units that start

   * with "ABC", so ABC301, ABC299, ABC741 etc. This method is non-trivial so it

   * would help to first implement the helper method matchesDiscipline (below).

   *

   * @param discipline

   * @return

   */

   public static Set<String> getStudents(String discipline) {

       return enrollments.get(discipline);

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote