Package assignment

Class University

java.lang.Object
assignment.University

public class University extends Object
CSCU9A3 Assignment
University.java

University maintains an ArrayList called Modules that stores the list of modules offered by the university.

Your task is to correctly implement method bodies for:

binarySearch()
mergeSort()

The above methods are called via public methods of the same name which supply the local modules object as a parameter. You can observe calls to these public methods in the go methods of UniversityTest.java
Since:
1.0
Version:
01.11.2020
Author:
2629330
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private ArrayList<Module>
    The array list containing the modules.
  • Constructor Summary

    Constructors
    Constructor
    Description
    A new University object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add a module.
    This method should use a binary search approach to find for the Module (based on the name) in the ArrayList.
    protected Module
    This method should use a binary search approach to find for the Module (based on its name) in the ArrayList 'modules'.
    void
    Clear the modules.
    void
    Show the module list.
    find(int val, String name)
    This method calls the find method for a specific module.
    inWalk(int val)
    This method calls the in-order traversal method for a specific module.
    mergeSort(boolean asc, String attr)
    This method should use a merge sort approach to rearrange the references in the ArrayList 'modules' such that they are in order according to the attr (attribute) parameter If asc is true, this should be ascending order If asc is false, this should be descending order You should not modify this code.
    protected ArrayList<Module>
    mergeSort(ArrayList<Module> list, boolean ascending, String attr)
    This method should use a merge sort approach to rearrange the references in ArrayList 'modules' such that they are in order according to the attr (attribute) parameter.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • modules

      private ArrayList<Module> modules
      The array list containing the modules.
  • Constructor Details

    • University

      public University()
      A new University object.
  • Method Details

    • clear

      public void clear()
      Clear the modules.
    • addModule

      public void addModule(Module v)
      Add a module.
      Parameters:
      v - the module to add.
    • describeModuleList

      public void describeModuleList()
      Show the module list.
    • inWalk

      public String inWalk(int val)
      This method calls the in-order traversal method for a specific module.
      Parameters:
      val - the index of the module that you want to call the inWalk method for.
      Returns:
      A string with the names of all students in the tree.
    • find

      public Person find(int val, String name)
      This method calls the find method for a specific module.
      Parameters:
      val - the index of the module that you want to call the inWalk method for.
      name - the name of the student.
      Returns:
      A return reference to the student that was found, or null if no student found.
    • binarySearch

      public Module binarySearch(String name)
      This method should use a binary search approach to find for the Module (based on the name) in the ArrayList. 'modules' - you should not modify this code.
      Parameters:
      name - module name to be found.
      Returns:
      The module that was found or null if no module found.
    • binarySearch

      protected Module binarySearch(ArrayList<Module> list, String name)
      This method should use a binary search approach to find for the Module (based on its name) in the ArrayList 'modules'.
      Parameters:
      list - an ArrayList of Modules objects to search.
      name - module name to be found.
      Returns:
      The module that was found, or null if no module found.
    • mergeSort

      public ArrayList<Module> mergeSort(boolean asc, String attr)
      This method should use a merge sort approach to rearrange the references in the ArrayList 'modules' such that they are in order according to the attr (attribute) parameter
      • If asc is true, this should be ascending order
      • If asc is false, this should be descending order
      You should not modify this code.
      Parameters:
      asc - true if the list should be ascending order, false for descending.
      attr - attribute (name or code) that will be used during the sorting.
      Returns:
      The ArrayList 'modules' that have been sorted using merge sort.
    • mergeSort

      protected ArrayList<Module> mergeSort(ArrayList<Module> list, boolean ascending, String attr)
      This method should use a merge sort approach to rearrange the references in ArrayList 'modules' such that they are in order according to the attr (attribute) parameter.
      • If asc is true, this should be ascending order
      • If asc is false, this should be descending order
      Parameters:
      list - the ArrayList to be sorted.
      ascending - true if list should be ascending order, false for descending.
      attr - attribute (name or code) that will be used during the sorting.
      Returns:
      The ArrayList 'modules' that have been sorted using merge sort.