Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

List Type Data Structures Overview : You will be implementing my version of a linked list. This is a linked list which has possible sublists

List Type Data Structures

Overview :

You will be implementing my version of a linked list. This is a linked list which has possible sublists descending from each node. These sublists are used to group together all nodes which share a common category value. You will be designing custom nodes with three categories on which to group. By the end you will have a list which is similar to the one shown below.

NOTE: The number of nodes here is for demonstration only. Your list should be able to dynamically add new nodes either to the main list, or a specific sublist based on the criteria described in the rest of these directions.

image text in transcribed

Observe that the main list is doubly-linked, while the sub-lists are not.

The Node Class

The Node class represents one "Node" of your LinkedList. The Node class must be Generic with three different parameterized types. The Generic types could each be different, so you cannot use the same generic label for each type. An example of what I mean is demonstrated in the following Node instantiation:

Node myNode = new Node(); The following defines the requirements for the Node class. You are not allowed to change / add / omit anything in the requirements.

Member Variables

This class shall have one member variable called category1 which will store information related to the first grouping category. This data field shall be generic and shall have package-level access.

This class shall have one member variable called category2 which will store information related to the second grouping category. This data field shall be generic and shall have package-level access.

This class shall have one member variable called category3 which will store information related to the third grouping category. This data field shall be generic and shall have package-level access.

This class shall have one member variable called right which is a pointer to the next item in the main list. This data field shall have package-level access.

This class shall have one member variable called left which is a pointer to the previous item in the main list. This data field shall have package-level access.

This class shall have one member variable called down which is a pointer to the next item in the sub-list This data field shall have package-level access.

No other member variables are allowed.

Constructor

This class shall have one constructor which has parameters to initialize the three category data fields.

No other constructors are allowed.

Methods:

This class shall have getters for each of the three category variables.

Node node = new Node(27, "blue", "musician");

NOTE: That all Node instantiation and manipulation will be done within your LinkedList class. The types for the parameters will also come from the corresponding generic parameters in the LinkedList class. Nodes will NOT be instantiated in any classes OTHER than LinkedList.

The LinkedList Class

This will be the class which is responsible for all of the functionality of your LinkedList. This must be a Genericclass where the generic parameter types could each be different. An example of instantiating a LinkedList might be:

LinkedList list = new LinkedList();

NOTE: The parameterized types will be the same type and in the same order as the parameterized types for the Nodes for this list.

The key with properly designing this class is in how a new node is added to your list. All nodes will be grouped together based on one of the three categories from the Node class. At any given time, the user can choose how to group the nodes, and the initial grouping will always use the first category. Nodes which have the same value in the current grouping category. will be added to the same sub-list. Nodes which do not have the same value as any of the existing sub-lists will be added to the main list.

Example: Lets say I have five people P1, P2, P3, P4, and P5, and each person has the following values in their respective categories (age, eye color, profession):

P1: 25, blue, doctor P2: 34, brown, pilot P3: 25, brown, uber driver P4: 25, green, doctor P5: 34, green, uber driver

If I were to group my list based on the age category (category1), my list might look something like:

image text in transcribed

You should also be able to regroup your list based on the other two categories as well.

Member Variables:

This class shall have one member variable called head which will store a pointer to the first Node in the LinkedList.

This class shall have one member variable called size which will store the total number of elements in the list (this includes all nodes in the main list as well as the sub lists). This should be a read-only property which cannot be changed outside of the LinkedList class.

This class shall have one member variable called category1Label which will store the label for category1 from the Node class. This should be a read-only property which cannot be changed once the initial list has been created. In the above example, the label for category1 would be "Age".

This class shall have one member variable called category2Label which will store the label for category2 from the Node class. This should be a read-only property which cannot be changed once the initial list has been created. In the above example, the label for category1 would be "Eye Color".

This class shall have one member variable called category3Label which will store the label for category1 from the Node class. This should be a read-only property which cannot be changed once the initial list has been created. In the above example, the label for category1 would be "Profession".

This class shall have one member variable called groupingCategory which will store the current category number upon which the list should be grouped. The default grouping category is category1.

No other member variables are allowed.

Constructors:

This class shall have one no-arg constructor which creates an empty list.

This class shall have one constructor which takes an integer parameter, which is the number of the current category upon which you want your list to group. This constructor should also create an empty list.

This class shall have one constructor which takes a File object parameter and an integer parameter. This File is the input file from which a list can be generated and populated. The integer parameter is the current grouping property. See below for the required format of the input file. This constructor should take the File and create a list based on the values in the File.

Methods:

NOTE: These methods should be implemented with generics in mind. It will be your job to figure out how to do this.

add(value1, value2, value3):

This method shall have three parameters. These parameters are the values of the categories in a Node.

Use the parameters to create a new Node and add it to the list.

The Node must be added in such a way that it maintains the current grouping category of the list.

clear():

This method shall clear the list.

deleteFirst():

This method shall delete the first Node in the main list.

This method shall NOT delete any nodes in the first Node's sublist. The remaining Nodes in the sublist should be "reattached" to the beginning of the main list.

deleteLast():

This method shall delete the last Node in the main list.

This method shall NOT delete any nodes in the last Node's sublist. The remaining Nodes in the sublist should be "reattached" to the end of the main list.

delete(mainIndex, subIndex):

This method shall delete a specific node from anywhere in the list, given the mainIndex and subIndex.

This method should ONLY delete the requested Node and should "reconnect" any Nodes that may be attached to the deleted Node.

get(mainIndex, category):

This method shall have an integer parameter, mainIndex, which is an index (starting from 0) which indicates the Node from the main branch you want to retrieve.

This method shall have another integer parameter, category, which is a category number (1 - 3) that will indicate which category's value you want to retrieve.

This method shall return the chosen category value, from the chosen Node in the main list. The category value should be returned as a String.

If the index is out of bounds, this method should throw an IndexOutOfBoundsException with an appropriate error message indicating whether it was the main index or category value that was out of bounds.

get(mainIndex, subIndex, category):

This method shall have an integer parameter, mainIndex, which is an index (starting from 0) which indicates the Node from the main branch you want to retrieve.

This method shall have an integer parameter, subIndex, which is an index (starting from 0) which indicates the Node from the sub-list of the chosen main branch Node.

This method shall have another integer parameter, category, which is a category number (1 - 3) that will indicate which category's value you want to retrieve.

This method shall return the value from the chosen category, in the indicated sub-list. The category value should be returned as a String.

If any of the parameters are out of bounds, this method should throw an IndexOutOfBoundsException with an appropriate error message indicating whether it was the main index, sub index or category value that was out of bounds.

regroup(groupingCategoryNumber):

This method shall be responsible for regrouping your LinkedList based on the given regrouping category number.

Example: I could take the above list from the diagram, which was initially grouped based on the Age category (category 1), and I could regroup the list based on the Profession category (category 3).

If the groupingCategoryNumber is out of bounds, display an IndexOutOfBoundsException with an appropriate error message.

size():

This method shall return the size of the main list.

The size is the number of nodes in the main list.

size(index):

This method shall return the size of the sub-list at the given index.

If the given index is out of bounds, this method should throw an IndexOutOfBoundsException with an appropriate error message.

No other methods are allowed, except you may add a toString() method for testing purposes only.

Input File Format

The input file shall be in the following format:

The first three lines of the file will be the labels of each category

The next line is a blank line

The values for each category are comma separated, with one node's values per line.

example:

Age Eye Color Profession 25, blue, doctor 34, brown, pilot 25, brown, uber driver 25, green, doctor 34, green, uber driver 

The GUI

Design a GUI which will display a graphical representation of your list. It should show the main list and any sub-lists in a diagram similar to what is pictured above.

The "nodes" should also display the values of the three categories stored in a node.

You must also provide a way for the user to manipulate the list using any of the previously designed methods.

Sub List(s) Main List

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions

Question

Connect with your audience

Answered: 1 week ago