Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help!!!! JAVA I done the project expect one part but I still give you all the detail that you needed... and I will post

please help!!!! JAVA

I done the project expect one part but I still give you all the detail that you needed...

and I will post my code please help me fix the CreateGrid() part in main and make GUI works 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 aGenericclass 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 IndexOutOfBoundsExceptionwith 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.

-------------------------------------------------I almost done everything but did not do that grip part please help me fix it ----------------------------------------

Main.java

import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage;

public class Main extends Application { Button regroupButt = new Button("Regroup List"); Button clearButt = new Button("Clear List"); Button fileButt = new Button("File"); Button sizeButt = new Button("Size of List"); Button quitButt = new Button("Quit"); Button addButt = new Button("Add Node to List"); Button delButt = new Button("Delete a Node"); Button getButt = new Button("Get Node information"); GridPane gp = new GridPane(); HBox hb = new HBox(); VBox vb = new VBox(); // File file = new File();

@Override public void start(Stage primaryStage) { try { primaryStage.setTitle("LinkedList");

hb.getStyleClass().add("hBox"); gp.getStyleClass().add("gridPane");

regroupButt.getStyleClass().add("button"); clearButt.getStyleClass().add("button"); fileButt.getStyleClass().add("button"); sizeButt.getStyleClass().add("button"); quitButt.getStyleClass().add("button"); addButt.getStyleClass().add("button"); delButt.getStyleClass().add("button"); getButt.getStyleClass().add("button");

Scene sc = new Scene(vb, 1000, 1000); sc.getStylesheets().add("style.css");

hb.getChildren().addAll(fileButt, addButt, delButt, clearButt, getButt, regroupButt, sizeButt, quitButt);

vb.getChildren().addAll(hb, gp);

primaryStage.setScene(sc); primaryStage.show(); } catch (Exception e) { e.printStackTrace(); } } public void createGrid(){ }

public static void main(String[] args) { launch(args); } }

-------------------------------------------------------------------------------------------------------------------------------

Node.Java

public class Node { protected T category1; protected K category2; protected O category3; protected Node right = null; protected Node left = null; protected Node down = null;

public Node(T category1, K category2, O category3) { this.category1 = category1; this.category2 = category2; this.category3 = category3; }

public T getCategory1() { return category1; }

public K getCategory2() { return category2; }

public O getCategory3() { return category3; } }

----------------------------------------------------------------------------------------------------------------------------------------------

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner;

public class LinkedList { private Node head; private int size = 0; private T category1Label; private K category2Label; private O category3Label; private int groupingCategory;

public LinkedList() { this.head = null; }

public LinkedList(int currentCategory) { this.head = null; this.groupingCategory = currentCategory; }

/* * 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. . */ @SuppressWarnings("unchecked") public LinkedList(File file, int currentCategory) throws FileNotFoundException { this.groupingCategory = currentCategory; String lineOfData = ""; String[] field = { "" }; String values = ""; String[] singleValues = { "" };

Scanner fReader = new Scanner(file);

while (fReader.hasNextLine()) { lineOfData += fReader.nextLine(); lineOfData += " "; field = lineOfData.split(" "); } fReader.close();

this.category1Label = (T) field[0]; this.category2Label = (K) field[1]; this.category3Label = (O) field[2];

for (int HA = 4; HA

for (int LOL = 0; LOL

/* * 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. */ public void add(T value1, K value2, O value3) { Node newNode = new Node(value1, value2, value3); Node currentNode = this.head; boolean done = false; if (groupingCategory == 1) { if (this.head == null) { this.head = newNode; System.out.println("made first head"); } else { if (currentNode.category1.equals(value1)) { if (currentNode.down == null) { currentNode.down = newNode; System.out.println("added to first node downlist"); } else { Node tempCur = currentNode; while (tempCur.down != null) { tempCur = tempCur.down; } tempCur.down = newNode; System.out.println("added to first node down list p2"); } } else { while (currentNode.right != null) { currentNode = currentNode.right; if (currentNode.category1.equals(value1)) { if (currentNode.down == null) { currentNode.down = newNode; System.out.println("added to middle node downlist"); done = true; } else { Node tempCur = currentNode; while (tempCur.down != null) { tempCur = tempCur.down; } tempCur.down = newNode; System.out.println("added to middle node down list p2"); done = true; } } } if (!done) { currentNode.right = newNode; newNode.left = currentNode; System.out.println("created a new node in main list"); } } } } else if (groupingCategory == 2) { if (this.head == null) { this.head = newNode; System.out.println("made first head"); } else { if (currentNode.category2.equals(value2)) { if (currentNode.down == null) { currentNode.down = newNode; System.out.println("added to first node downlist"); } else { Node tempCur = currentNode; while (tempCur.down != null) { tempCur = tempCur.down; } tempCur.down = newNode; System.out.println("added to first node down list p2"); } } else { while (currentNode.right != null) { currentNode = currentNode.right; if (currentNode.category2.equals(value2)) { if (currentNode.down == null) { currentNode.down = newNode; System.out.println("added to middle node downlist"); done = true; } else { Node tempCur = currentNode; while (tempCur.down != null) { tempCur = tempCur.down; } tempCur.down = newNode; System.out.println("added to middle node down list p2"); done = true; } } } if (!done) { currentNode.right = newNode; newNode.left = currentNode; System.out.println("created a new node in main list"); } } } } else if (groupingCategory == 3) { if (this.head == null) { this.head = newNode; System.out.println("made first head"); } else { if (currentNode.category3.equals(value3)) { if (currentNode.down == null) { currentNode.down = newNode; System.out.println("added to first node downlist"); } else { Node tempCur = currentNode; while (tempCur.down != null) { tempCur = tempCur.down; } tempCur.down = newNode; System.out.println("added to first node down list p2"); } } else { while (currentNode.right != null) { currentNode = currentNode.right;

if (currentNode.category3.equals(value3)) { if (currentNode.down == null) { currentNode.down = newNode; System.out.println("added to middle node downlist"); done = true; } else { Node tempCur = currentNode; while (tempCur.down != null) { tempCur = tempCur.down; } tempCur.down = newNode; System.out.println("added to middle node down list p2"); done = true; } } } if (!done) { currentNode.right = newNode; newNode.left = currentNode; System.out.println("created a new node in main list"); } } } } size++; System.out.println(size); }

/* This method shall clear the list. */ public void clear() { this.head = null; this.size = 0; }

/* * 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. */ public void deleteFirst() { if (this.size == 0) { System.out.println("Empty List"); } else { if (this.head.down != null) { this.head.right.left = this.head.down; this.head.down.right = this.head.right; this.head = this.head.down; } else { this.head = this.head.right; } this.size--; } }

/* * 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. */ public void deleteLast() { if (this.size == 0) { System.out.println("Empty List"); } else { Node currentNode = this.head; Node previousNode = this.head; while (currentNode.right != null) { previousNode = currentNode; currentNode = currentNode.right; }

if (currentNode.down != null) { currentNode.down.left = previousNode; previousNode.right = currentNode.down; } else { previousNode.right = null; } size--; } }

/* * 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. */ public void delete(int mainIndex, int subIndex) { int countMain = 0, countSub = 0; if (mainIndex > size() - 1 || mainIndex size(mainIndex) || subIndex

if (mainIndex == 0 && subIndex == 0) { deleteFirst(); } else if (mainIndex == size() - 1 && subIndex == 0) { deleteLast(); }

Node currentNode = this.head; Node previousNode = this.head; while (currentNode.right != null && countMain

while (currentNode.down != null && countSub

Node rightReference = currentNode.right; Node leftReference = currentNode.left;

if (subIndex == 0) { if (currentNode.down != null) { rightReference.left = currentNode.down; leftReference.right = currentNode.down; currentNode.down.right = rightReference; currentNode.down.left = leftReference; } else { rightReference.left = leftReference; leftReference.right = rightReference; } size--; } else if (subIndex > 0) { if (currentNode.down != null) { previousNode.down = currentNode.down; } else { previousNode.down = null; }

} }

/* * 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. */ public String get(int mainIndex, int category) { if (mainIndex > size() - 1 || mainIndex 3) { throw new IndexOutOfBoundsException("category index out of bounds"); }

int count = 0; Node currentNode = this.head; if (category == 1) { while (currentNode.right != null && count

return null; }

public String get(int mainIndex, int subIndex, int category) { if (mainIndex > size() - 1 || mainIndex 3) { throw new IndexOutOfBoundsException("category index out of bounds"); } else if (subIndex size(mainIndex)) { throw new IndexOutOfBoundsException("sub index out of bounds"); } int countMain = 0, countSub = 0; Node currentNode = this.head; if (category == 1) { while (currentNode.right != null && countMain

return null; }

/* * 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. */ public void regroup(int groupingCategoryNumber) { if (groupingCategoryNumber 3) { throw new IndexOutOfBoundsException("grouping category number out of bounds, bounds = [0,3]"); } else { this.groupingCategory = groupingCategoryNumber; ArrayList> listOfNodes = new ArrayList();

Node mainNode = this.head; Node subNode = this.head; while (mainNode != null) { listOfNodes.add(mainNode); while(subNode.down != null){ subNode = subNode.down; listOfNodes.add(subNode); } mainNode = mainNode.right; subNode = mainNode; } clear(); for (int i = 0; i

}

/* * This method shall return the size of the main list. The size is the * number of nodes in the main list. */ public int size() { Node currentNode = this.head; int mainListSize = 1; while (currentNode.right != null) { currentNode = currentNode.right; mainListSize++; } return mainListSize; }

/* * 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. */ public int size(int index) { int count = 0; int subListSize = 0; if (index > size() - 1 || index thisNode = this.head; while (thisNode.down != null) { thisNode = thisNode.down; subListSize++; } } else { Node currentNode = this.head; while (currentNode.right != null && count

public void print() { // System.out.println(this.head.right.getCategory1()); // System.out.println(this.head.down.getCategory1()); // System.out.println(this.head.down.down.getCategory1()); // // System.out.println(this.head.right.right.left.down.getCategory2());

System.out.println(this.head.right.right.getCategory3()); }

public void print2() { System.out.println(this.head.getCategory1()); System.out.println(this.head.down.getCategory1()); System.out.println(this.head.down.down.getCategory1()); } }

-------------------------------------------------------------

style.css

.hBox{ -fx-background-color: #000000; } .gridPane{ -fx-pref-height: 1000.0; -fx-pref-width: 900.0; -fx-background-color: #000000; } .button{ -fx-background-color: #000000; -fx-border-color: #ffffff; -fx-text-fill: #ffffff; }

-------------------------------------------------------------------------------

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions