Data Structures and Collection Framework

Posted 20 February 2011 - 12:45 PM

I am given four classes that I should make use of various data structures some to be used in the Java Collections Framework and some to construct my self such as: breadth first, I am also suppose to use an array, a linked list, a tree or a combination of these.

The program must be capable of modelling the hierarchical relationships between parts in an assembly. The application detail:
A factory is set up to assemble artefacts that are made up of parts. Those parts may themselves be constructed of sub-parts. For example, a shed might be made up of a door, two end walls, two side walls and a roof. The door consists of a door panel, 3 hinges and 6 size 8 screws. In general, artefacts are made up of parts which are themselves made of parts

I am asked to implement an application that supports a hierarchy in which parts are made up from other parts, which themselves may be made of other parts (to n levels).

The PartsInformationRepository provides a framework in which to develop the application. I am asked to implement the methods in the PartsRepository class and may need to make other changes/add additional classes to the code that is provided.

The application described above needs to ensure that neither direct nor indirect recursive components are specified. I.e. the application needs to check that parts are not specified such that A contains B which contains C which contains A. This functionality has to be implemented also.

The application should support the following functionality:
Add a part.
For a given part number, display its detail
Link a part as a direct sub-component of another part
For a given part number, list its direct components
For a given part number, list all direct assemblies in which it is used
For a given part number, list all assemblies up to the final product in which it is used
For a given part number, list all sub-components down to the lowest level
List n-levels of assemblies above a given part number
List n-levels of components below a given part number

Firstly I am suppose to start with adding a part in the PartsRepository class. How can I do this?

Replies To: Data Structures and Collection Framework

Re: Data Structures and Collection Framework

Based on the problem description, it might help you visualize (conceptualize) the answer to your question, (paraphrased) "How do I add a part?" if you think:

- the PartsRepository is a collection of parts
- parts can contain (or include) other parts

As an example, partA, partB, partC, and partD are all parts in your parts repository. They are all instantiations of class Part. ( Part partA = new Part();, Part partB = new Part();, etc. ). If partA contains partB and partC, then partB and partC would be 'added' to your parts repository by the method addPart( Part part ), as in:

partA.addPart( partB );
partA.addPart( partC );

and if partC includes partD, then you'd add partD to the parts repository using:

partC.addPart( partD );

Just something to get you thinking about the design. Think about it, code some, and come back when you need more help.

Re: Data Structures and Collection Framework

Posted 20 February 2011 - 04:43 PM

There may be, AND I SAID MAY BE before being prosecuted, a misconception here
The Collection Framework is not to organize data on disk they are usefull tools on how to process data when it is in memory
The way data is stored is irrelevant, when you have your data in memory then you can process it in multiple (many times redundant ways) offered by the Collection Framework