Question

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.

Sub List(s) Main List

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<Integer, String, Double> myNode = new Node<Integer, String, Double>();

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<Integer, String, String> node = new Node<Integer, String, String>(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<Integer, String, String> list = new LinkedList<Integer, String, String>();

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:

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<T, K, O> {
protected T category1;
protected K category2;
protected O category3;
protected Node<T, K, O> right = null;
protected Node<T, K, O> left = null;
protected Node<T, K, O> 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<T, K, O> {
private Node<T, K, O> 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 < field.length; HA++) {
values += field[HA];
values += ", ";
singleValues = values.split(", ");
}

for (int LOL = 0; LOL < singleValues.length; LOL += 3) {
add((T) singleValues[LOL], (K) singleValues[LOL + 1], (O) singleValues[LOL + 2]);
}
}

/*
* 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<T, K, O> newNode = new Node<T, K, O>(value1, value2, value3);
Node<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> currentNode = this.head;
Node<T, K, O> 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 < 0) {
throw new IndexOutOfBoundsException("main index out of bounds");
} else if (subIndex > size(mainIndex) || subIndex < 0) {
throw new IndexOutOfBoundsException("sub index out of bounds");
}

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

Node<T, K, O> currentNode = this.head;
Node<T, K, O> previousNode = this.head;
while (currentNode.right != null && countMain < mainIndex) {
previousNode = currentNode;
currentNode = currentNode.right;
countMain++;
}

while (currentNode.down != null && countSub < subIndex) {
previousNode = currentNode;
currentNode = currentNode.down;
countSub++;
}

Node<T, K, O> rightReference = currentNode.right;
Node<T, K, O> 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 < 0) {
throw new IndexOutOfBoundsException("mainIndex out of bounds");
} else if (category < 0 || category > 3) {
throw new IndexOutOfBoundsException("category index out of bounds");
}

int count = 0;
Node<T, K, O> currentNode = this.head;
if (category == 1) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory1();
} else if (category == 2) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory2();
} else if (category == 3) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory3();
}

return null;
}

  
public String get(int mainIndex, int subIndex, int category) {
if (mainIndex > size() - 1 || mainIndex < 0) {
throw new IndexOutOfBoundsException("main index out of bounds");
} else if (category < 0 || category > 3) {
throw new IndexOutOfBoundsException("category index out of bounds");
} else if (subIndex < 0 | subIndex > size(mainIndex)) {
throw new IndexOutOfBoundsException("sub index out of bounds");
}
int countMain = 0, countSub = 0;
Node<T, K, O> currentNode = this.head;
if (category == 1) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory1();
} else if (category == 2) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory2();
} else if (category == 3) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory3();
}

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 < 1 || groupingCategoryNumber > 3) {
throw new IndexOutOfBoundsException("grouping category number out of bounds, bounds = [0,3]");
} else {
this.groupingCategory = groupingCategoryNumber;
ArrayList<Node<T, K, O>> listOfNodes = new ArrayList<>();

Node<T, K, O> mainNode = this.head;
Node<T, K, O> 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 < listOfNodes.size(); i++) {
add(listOfNodes.get(i).getCategory1(),listOfNodes.get(i).getCategory2(),listOfNodes.get(i).getCategory3());
}
}

}

/*
* 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<T, K, O> 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 < 0) {
throw new IndexOutOfBoundsException("Index out of bounds, index bounds: [0," + size() + "]");
} else {
if (index == 0) {
Node<T, K, O> thisNode = this.head;
while (thisNode.down != null) {
thisNode = thisNode.down;
subListSize++;
}
} else {
Node<T, K, O> currentNode = this.head;
while (currentNode.right != null && count < index) {
currentNode = currentNode.right;
count++;
}
while (currentNode.down != null) {
currentNode = currentNode.down;
subListSize++;
}
}
}
return subListSize;
}

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;
}

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

i make changes the program and run it

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<T, K, O> {
protected T category1;
protected K category2;
protected O category3;
protected Node<T, K, O> right = null;
protected Node<T, K, O> left = null;
protected Node<T, K, O> 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<T, K, O> {
private Node<T, K, O> 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 < field.length; HA++) {
values += field[HA];
values += ", ";
singleValues = values.split(", ");
}

for (int LOL = 0; LOL < singleValues.length; LOL += 3) {
add((T) singleValues[LOL], (K) singleValues[LOL + 1], (O) singleValues[LOL + 2]);
}
}

/*
* 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<T, K, O> newNode = new Node<T, K, O>(value1, value2, value3);
Node<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> 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<T, K, O> currentNode = this.head;
Node<T, K, O> 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 < 0) {
throw new IndexOutOfBoundsException("main index out of bounds");
} else if (subIndex > size(mainIndex) || subIndex < 0) {
throw new IndexOutOfBoundsException("sub index out of bounds");
}

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

Node<T, K, O> currentNode = this.head;
Node<T, K, O> previousNode = this.head;
while (currentNode.right != null && countMain < mainIndex) {
previousNode = currentNode;
currentNode = currentNode.right;
countMain++;
}

while (currentNode.down != null && countSub < subIndex) {
previousNode = currentNode;
currentNode = currentNode.down;
countSub++;
}

Node<T, K, O> rightReference = currentNode.right;
Node<T, K, O> 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 < 0) {
throw new IndexOutOfBoundsException("mainIndex out of bounds");
} else if (category < 0 || category > 3) {
throw new IndexOutOfBoundsException("category index out of bounds");
}

int count = 0;
Node<T, K, O> currentNode = this.head;
if (category == 1) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory1();
} else if (category == 2) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory2();
} else if (category == 3) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory3();
}

return null;
}

  
public String get(int mainIndex, int subIndex, int category) {
if (mainIndex > size() - 1 || mainIndex < 0) {
throw new IndexOutOfBoundsException("main index out of bounds");
} else if (category < 0 || category > 3) {
throw new IndexOutOfBoundsException("category index out of bounds");
} else if (subIndex < 0 | subIndex > size(mainIndex)) {
throw new IndexOutOfBoundsException("sub index out of bounds");
}
int countMain = 0, countSub = 0;
Node<T, K, O> currentNode = this.head;
if (category == 1) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory1();
} else if (category == 2) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory2();
} else if (category == 3) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory3();
}

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 < 1 || groupingCategoryNumber > 3) {
throw new IndexOutOfBoundsException("grouping category number out of bounds, bounds = [0,3]");
} else {
this.groupingCategory = groupingCategoryNumber;
ArrayList<Node<T, K, O>> listOfNodes = new ArrayList<>();

Node<T, K, O> mainNode = this.head;
Node<T, K, O> 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 < listOfNodes.size(); i++) {
add(listOfNodes.get(i).getCategory1(),listOfNodes.get(i).getCategory2(),listOfNodes.get(i).getCategory3());
}
}

}

/*
* 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<T, K, O> 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 < 0) {
throw new IndexOutOfBoundsException("Index out of bounds, index bounds: [0," + size() + "]");
} else {
if (index == 0) {
Node<T, K, O> thisNode = this.head;
while (thisNode.down != null) {
thisNode = thisNode.down;
subListSize++;
}
} else {
Node<T, K, O> currentNode = this.head;
while (currentNode.right != null && count < index) {
currentNode = currentNode.right;
count++;
}
while (currentNode.down != null) {
currentNode = currentNode.down;
subListSize++;
}
}
}
return subListSize;
}

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;
}

Add a comment
Know the answer?
Add Answer to:
please help!!!! JAVA I done the project expect one part but I still give you all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with todo line please public class LinkedList { private Node head; public LinkedList()...

    I need help with todo line please public class LinkedList { private Node head; public LinkedList() { head = null; } public boolean isEmpty() { return head == null; } public int size() { int count = 0; Node current = head; while (current != null) { count++; current = current.getNext(); } return count; } public void add(int data) { Node newNode = new Node(data); newNode.setNext(head); head = newNode; } public void append(int data) { Node newNode = new Node(data);...

  • This Individual Assignment is a set of three problems. The first is a recursion "warm up"...

    This Individual Assignment is a set of three problems. The first is a recursion "warm up" exercise, and the second two are QuickSort variations. The "warm up" should be implemented as a static method in your main App class and the second two will use additional classes (as instructed below). All three problems should be included in the same NetBeans project (exported to ZIP as usual). ----------------- All of your classes should be properly encapsulated, follow all proper coding conventions...

  • I am trying to make a linked list queue and I am trying to use the...

    I am trying to make a linked list queue and I am trying to use the display method I made just to see if its working but when I run it nothing is displayed please help. Also the newPlane boolean was made just so I can randomly decide if the plane is going to join the queue or not. public class PlaneSimulation { public static void main(String[] args) { int landTime = 2; int takeoffTime = 3; int avgArrivalInterval =...

  • P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList()...

    P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList() { header = null; } public final Node Search(int key) { Node current = header; while (current != null && current.item != key) { current = current.link; } return current; } public final void Append(int newItem) { Node newNode = new Node(newItem); newNode.link = header; header = newNode; } public final Node Remove() { Node x = header; if (header != null) { header...

  • Java Programming: The following is my code: public class KWSingleLinkedList<E> {    public void setSize(int size)...

    Java Programming: The following is my code: public class KWSingleLinkedList<E> {    public void setSize(int size)    {        this.size = size;    }    /** Reference to list head. */    private Node<E> head = null;    /** The number of items in the list */    private int size = 0;       /** Add an item to the front of the list.    @param item The item to be added    */    public void addFirst(E...

  • Consider java for fixing this code please: what i need is to insert method to be...

    Consider java for fixing this code please: what i need is to insert method to be added ( please don't change the test class and any giving value in the first class ) here is the correct out put: ------------------testAddLast()---- {A} {A->B} {A->B->null} {A->B->null->C} ----------------------------- --------testSubListOfSmallerValues()---------- {} {B->B->B->A} {F->B->B->B->A->D} {F->B->B->G->B->A->M->D} ----------------------------- ------------Test lastIndexOf()----- -1 3 -1 -1 0 5 2 ----------------------------- ---------testRetainAll()--------- {} {6:Tony->6:Tony} {null->bad->null} ----------------------------- ---------------Test removeStartingAtBack--- false true {apple->null->bad->null} true {apple->null->bad} {2:Morning->3:Abby->4:Tim->5:Tom->6:Tony} ----------------------------- ---------test insertionSort()--------- {} {D} {D->E->E->F->G}...

  • In C++, for the provided template linked list class create a derived class of it which...

    In C++, for the provided template linked list class create a derived class of it which adds the functionality to it to find the high and low value of any given data stored in the list. The derived class must be a template. LinkedList.h #pragma once #include <iostream> using namespace std; template <class T> class ListNode {    public:        T data;        ListNode<T>* next;        ListNode(T data)        {            this->data = data;...

  • Problem 3 (List Implementation) (35 points): Write a method in the DoublyLList class that deletes the...

    Problem 3 (List Implementation) (35 points): Write a method in the DoublyLList class that deletes the first item containing a given value from a doubly linked list. The header of the method is as follows: public boolean removeValue(T aValue) where T is the general type of the objects in the list and the methods returns true if such an item is found and deleted. Include testing of the method in a main method of the DoublyLList class. ------------------------------------------------------------------------------------- /** A...

  • 9.8 LAB: Finding the first and last occurrence of a value (doubly-linked list) Given main() and...

    9.8 LAB: Finding the first and last occurrence of a value (doubly-linked list) Given main() and a PeopleNode class, complete the PeopleList class by writing findFirst() and findLast() methods. The findFirst() method should find the first occurrence of an age value in the linked list and return the corresponding node. Similarly, the findLast() method should find the last occurrence of the age value in the linked list and return the corresponding node. For both methods, if the age value is...

  • could somone please help me to complete this ! public class MyLinkedList<AnyType> { private Node<AnyType> head,...

    could somone please help me to complete this ! public class MyLinkedList<AnyType> { private Node<AnyType> head, tail; private int size; public MyLinkedList() { this.head = null; this.tail = null; this.size = 0; } //1.Insert a node at the end of the list public void insert(AnyType data) { Node<AnyType> newNode = new Node(); newNode.data = data; if (head == null) { head = newNode; tail = newNode; head.next = null; tail.next = null; } else { tail.next = newNode; tail =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT