Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA HELP HELP HELP me fix it... Buttons do not work.... idk what are the problems import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import

JAVA HELP HELP HELP me fix it...

Buttons do not work.... idk what are the problems

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("styles/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); } }

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

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 < 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 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 < 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 currentNode = this.head; Node 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 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 < 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 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 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> 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 < 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 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 thisNode = this.head; while (thisNode.down != null) { thisNode = thisNode.down; subListSize++; } } else { Node 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()); } }

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

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

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

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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions