Package assignment
Class University
java.lang.Object
assignment.University
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()
- Since:
- 1.0
- Version:
- 01.11.2020
- Author:
- 2629330
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a module.binarySearch
(String name) This method should use a binary search approach to find for the Module (based on the name) in the ArrayList.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'.void
clear()
Clear the modules.void
Show the module list.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.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.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.
-
Field Details
-
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
Add a module.- Parameters:
v
- the module to add.
-
describeModuleList
public void describeModuleList()Show the module list. -
inWalk
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
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
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
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
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
- 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
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.
-