SlideShare a Scribd company logo
can you add a delete button and a add button to the below program. java fx
package nusoft;
public class Car {
private String make;
private String model;
private int year;
private String color;
public Car(String make, int year, String model, String color) {
this.make = make;
this.model = model;
this.year = year;
this.color = color;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Override
public String toString() {
return year + " " + make + " " + model + " (" + color + ")";
}
}
package nusoft;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class CarNavigator extends Application {
private ArrayList cars = new ArrayList<>();
private int currentIndex = 0;
@Override
public void start(Stage primaryStage) throws Exception {
readCarsFile();
Label carLabel = new Label();
carLabel.setAlignment(Pos.CENTER);
updateCarLabel(carLabel);
Button prevButton = new Button("Previous");
prevButton.setOnAction(e -> {
currentIndex--;
if (currentIndex < 0) {
currentIndex = cars.size() - 1;
}
updateCarLabel(carLabel);
});
Button nextButton = new Button("Next");
nextButton.setOnAction(e -> {
currentIndex++;
if (currentIndex >= cars.size()) {
currentIndex = 0;
}
updateCarLabel(carLabel);
});
VBox buttonBox = new VBox(10, prevButton, nextButton);
buttonBox.setAlignment(Pos.CENTER);
BorderPane root = new BorderPane(carLabel, null, null, buttonBox, null);
Scene scene = new Scene(root, 400, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
private void readCarsFile() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("cars.txt"));
String line;
while ((line = reader.readLine()) != null) {
cars.add(line);
}
reader.close();
}
private void updateCarLabel(Label label) {
label.setText(cars.get(currentIndex));
}
public static void main(String[] args) {
launch(args);
}
}
package nusoft.utils;
import java.util.NoSuchElementException;
import nusoft.Car;
public class NuLinkedList {
private Node head;
private Node tail;
private int size;
private static class Node {
E element;
Node prev;
Node next;
Node(E element, Node prev, Node next) {
this.element = element;
this.prev = prev;
this.next = next;
}
}
public boolean contains(E e) {
return indexOf(e) != -1;
}
public E get(int index) {
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException();
}
return getNode(index).element;
}
public int indexOf(E e) {
int index = 0;
for (Node node = head; node != null; node = node.next) {
if (e == null ? node.element == null : e.equals(node.element)) {
return index;
}
index++;
}
return -1;
}
public int lastIndexOf(E e) {
int index = size - 1;
for (Node node = tail; node != null; node = node.prev) {
if (e == null ? node.element == null : e.equals(node.element)) {
return index;
}
index--;
}
return -1;
}
public E set(int index, E e) {
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException();
}
Node node = getNode(index);
E oldElement = node.element;
node.element = e;
return oldElement;
}
public void add(E e) {
addLast(e);
}
public void add(int index, E e) {
if (index < 0 || index > size) {
throw new IndexOutOfBoundsException();
}
if (index == size) {
addLast(e);
} else {
addBefore(getNode(index), e);
}
}
public void addFirst(E e) {
if (size == 0) {
head = tail = new Node<>(e, null, null);
} else {
head.prev = new Node<>(e, null, head);
head = head.prev;
}
size++;
}
public void addLast(E e) {
if (size == 0) {
head = tail = new Node<>(e, null, null);
} else {
tail.next = new Node<>(e, tail, null);
tail = tail.next;
}
size++;
}
public E remove(int index) {
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException();
}
return remove(getNode(index));
}
public E removeFirst() {
if (size == 0) {
throw new NoSuchElementException();
}
return remove(head);
}
public E removeLast() {
if (size == 0) {
throw new NoSuchElementException();
}
return remove(tail);
}
public int size() {
return size;
}
private Node getNode(int index) {
if (index < size / 2) {
Node node = head;
for (int i = 0;i < index; i++) {
node = node.next;
}
return node;
} else {
Node node = tail;
for (int i = size - 1; i > index; i--) {
node = node.prev;
}
return node;
}
}
private void addBefore(Node node, E e) {
Node newNode = new Node<>(e, node.prev, node);
node.prev.next = newNode;
node.prev = newNode;
size++;
}
private E remove(Node node) {
if (node == head) {
head = node.next;
} else {
node.prev.next = node.next;
}
if (node == tail) {
tail = node.prev;
} else {
node.next.prev = node.prev;
}
size--;
return node.element;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("[");
for (Node node = head; node != null; node = node.next) {
if (node != head) {
sb.append(", ");
}
sb.append(node.element);
}
sb.append("]");
return sb.toString();
}
public void remove(Car lastCar) {
// TODO Auto-generated method stub
}
}
( import java. io. BufferedReader;

More Related Content

PDF
import java-util--- public class MyLinkedList{ public static void.pdf
PDF
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
PDF
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
PDF
TypeScript Introduction
PDF
How do you update an address according to this code- Currently- I fig.pdf
PDF
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
PDF
Hi, Please find my code.I have correted all of your classes.Plea.pdf
PDF
There is something wrong with my program-- (once I do a for view all t.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
TypeScript Introduction
How do you update an address according to this code- Currently- I fig.pdf
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
Hi, Please find my code.I have correted all of your classes.Plea.pdf
There is something wrong with my program-- (once I do a for view all t.pdf

Similar to can you add a delete button and a add button to the below program. j.pdf (20)

PDF
So I have this code(StackInAllSocks) and I implemented the method but.pdf
PDF
Scala vs Java 8 in a Java 8 World
PDF
Scala in practice
PDF
I need help implementing a Stack with this java programming assignme.pdf
PDF
in this assignment you are asked to write a simple driver program an.pdf
PPT
Java Generics
PDF
Rewrite this code so it can use a generic type instead of integers. .pdf
PDF
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
PDF
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
PDF
Given below is the completed implementation of MyLinkedList class. O.pdf
PDF
6. Generics. Collections. Streams
PDF
Manual tecnic sergi_subirats
PPT
computer notes - Data Structures - 3
DOCX
This code currently works... Run it and get a screen shot of its .docx
DOCX
Java programs
PPTX
Nice to meet Kotlin
PPT
Data structures cs301 power point slides lecture 03
PDF
Having a problem figuring out where my errors are- The code is not run.pdf
PDF
This is to test a balanced tree. I need help testing an unbalanced t.pdf
PDF
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
Scala vs Java 8 in a Java 8 World
Scala in practice
I need help implementing a Stack with this java programming assignme.pdf
in this assignment you are asked to write a simple driver program an.pdf
Java Generics
Rewrite this code so it can use a generic type instead of integers. .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
6. Generics. Collections. Streams
Manual tecnic sergi_subirats
computer notes - Data Structures - 3
This code currently works... Run it and get a screen shot of its .docx
Java programs
Nice to meet Kotlin
Data structures cs301 power point slides lecture 03
Having a problem figuring out where my errors are- The code is not run.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdf
Ad

More from sales88 (20)

PDF
Caso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdf
PDF
CASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdf
PDF
Caso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdf
PDF
Caso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdf
PDF
CASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdf
PDF
CASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdf
PDF
Caso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdf
PDF
Caso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdf
PDF
Caso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdf
PDF
Caso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdf
PDF
Caso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdf
PDF
Caso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdf
PDF
Caso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdf
PDF
Caso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdf
PDF
Caso 1 Felipe R�os y Tiffany De Los Rios married filling jointl.pdf
PDF
Case studyData Protect and PrivacyHuman beings value their priva.pdf
PDF
CASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdf
PDF
case study Private Practice Implements Safeguards for Waiting .pdf
PDF
Case Study Liberty and the Elderly Patient Ronald is 71 years old..pdf
PDF
Case Study AMr. P tripped and broke her left hip while attempting.pdf
Caso de empresa Hamburguesa In-N-Out el valor del cliente a la an.pdf
CASO 6.2 Algunos ciudadanos preocupados hicieron una cita para reu.pdf
Caso de EstudioLiderazgo y Gesti�nLaura es directora asocia.pdf
Caso de estudio Hacer que las alianzas estrat�gicas y las redes f.pdf
CASO DE ESTUDIO La cl�nica Mayo es uno de los nombres m�s respetad.pdf
CASO DE ESTUDIO La �pera de Sydney es uno de los edificios ic�nico.pdf
Caso de estudio Despu�s de luchar con la deuda y la fuerte compete.pdf
Caso cl�nicoSDRAPregunta 1.Dados sus s�ntomas de fatiga, disne.pdf
Caso 21-3 Orden de prueba de deterioro Five Star Hotel Corporati.pdf
Caso 6.2 Seguro Mar�timo Cl�usula Inchmaree Un barco pesquero c.pdf
Caso 3.1 Firma de contadores Moss y McAdams Bruce Palmer hab�a t.pdf
Caso 2 (TV de Alta Definici�n La Gran Alianza) (1) Seg�n el caso .pdf
Caso 1 (8 puntos) Miguel y Cinthia Leatch viven en Covington, Ten.pdf
Caso 1 Agmmaglobulinemia ligada al X 1. Bill fue testamento duran.pdf
Caso 1 Felipe R�os y Tiffany De Los Rios married filling jointl.pdf
Case studyData Protect and PrivacyHuman beings value their priva.pdf
CASE STUDY [30 Marks] Former Tongaat Hulett bosses in court for frau.pdf
case study Private Practice Implements Safeguards for Waiting .pdf
Case Study Liberty and the Elderly Patient Ronald is 71 years old..pdf
Case Study AMr. P tripped and broke her left hip while attempting.pdf
Ad

Recently uploaded (20)

PPTX
Institutional Correction lecture only . . .
PDF
Complications of Minimal Access Surgery at WLH
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Types and Its function , kingdom of life
PPTX
Lesson notes of climatology university.
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
master seminar digital applications in india
PDF
01-Introduction-to-Information-Management.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cell Structure & Organelles in detailed.
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
VCE English Exam - Section C Student Revision Booklet
Institutional Correction lecture only . . .
Complications of Minimal Access Surgery at WLH
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Types and Its function , kingdom of life
Lesson notes of climatology university.
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
2.FourierTransform-ShortQuestionswithAnswers.pdf
O7-L3 Supply Chain Operations - ICLT Program
RMMM.pdf make it easy to upload and study
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
master seminar digital applications in india
01-Introduction-to-Information-Management.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cell Structure & Organelles in detailed.
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Module 4: Burden of Disease Tutorial Slides S2 2025
VCE English Exam - Section C Student Revision Booklet

can you add a delete button and a add button to the below program. j.pdf

  • 1. can you add a delete button and a add button to the below program. java fx package nusoft; public class Car { private String make; private String model; private int year; private String color; public Car(String make, int year, String model, String color) { this.make = make; this.model = model; this.year = year; this.color = color; } public String getMake() { return make; } public void setMake(String make) { this.make = make; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public int getYear() { return year; }
  • 2. public void setYear(int year) { this.year = year; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } @Override public String toString() { return year + " " + make + " " + model + " (" + color + ")"; } } package nusoft; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class CarNavigator extends Application { private ArrayList cars = new ArrayList<>(); private int currentIndex = 0; @Override
  • 3. public void start(Stage primaryStage) throws Exception { readCarsFile(); Label carLabel = new Label(); carLabel.setAlignment(Pos.CENTER); updateCarLabel(carLabel); Button prevButton = new Button("Previous"); prevButton.setOnAction(e -> { currentIndex--; if (currentIndex < 0) { currentIndex = cars.size() - 1; } updateCarLabel(carLabel); }); Button nextButton = new Button("Next"); nextButton.setOnAction(e -> { currentIndex++; if (currentIndex >= cars.size()) { currentIndex = 0; } updateCarLabel(carLabel); }); VBox buttonBox = new VBox(10, prevButton, nextButton); buttonBox.setAlignment(Pos.CENTER); BorderPane root = new BorderPane(carLabel, null, null, buttonBox, null); Scene scene = new Scene(root, 400, 200); primaryStage.setScene(scene); primaryStage.show(); } private void readCarsFile() throws IOException {
  • 4. BufferedReader reader = new BufferedReader(new FileReader("cars.txt")); String line; while ((line = reader.readLine()) != null) { cars.add(line); } reader.close(); } private void updateCarLabel(Label label) { label.setText(cars.get(currentIndex)); } public static void main(String[] args) { launch(args); } } package nusoft.utils; import java.util.NoSuchElementException; import nusoft.Car; public class NuLinkedList { private Node head; private Node tail; private int size; private static class Node { E element; Node prev; Node next; Node(E element, Node prev, Node next) { this.element = element; this.prev = prev; this.next = next; } } public boolean contains(E e) { return indexOf(e) != -1; }
  • 5. public E get(int index) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(); } return getNode(index).element; } public int indexOf(E e) { int index = 0; for (Node node = head; node != null; node = node.next) { if (e == null ? node.element == null : e.equals(node.element)) { return index; } index++; } return -1; } public int lastIndexOf(E e) { int index = size - 1; for (Node node = tail; node != null; node = node.prev) { if (e == null ? node.element == null : e.equals(node.element)) { return index; } index--; } return -1; } public E set(int index, E e) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(); } Node node = getNode(index); E oldElement = node.element; node.element = e; return oldElement; } public void add(E e) {
  • 6. addLast(e); } public void add(int index, E e) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(); } if (index == size) { addLast(e); } else { addBefore(getNode(index), e); } } public void addFirst(E e) { if (size == 0) { head = tail = new Node<>(e, null, null); } else { head.prev = new Node<>(e, null, head); head = head.prev; } size++; } public void addLast(E e) { if (size == 0) { head = tail = new Node<>(e, null, null); } else { tail.next = new Node<>(e, tail, null); tail = tail.next; } size++; } public E remove(int index) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(); } return remove(getNode(index)); }
  • 7. public E removeFirst() { if (size == 0) { throw new NoSuchElementException(); } return remove(head); } public E removeLast() { if (size == 0) { throw new NoSuchElementException(); } return remove(tail); } public int size() { return size; } private Node getNode(int index) { if (index < size / 2) { Node node = head; for (int i = 0;i < index; i++) { node = node.next; } return node; } else { Node node = tail; for (int i = size - 1; i > index; i--) { node = node.prev; } return node; } } private void addBefore(Node node, E e) { Node newNode = new Node<>(e, node.prev, node); node.prev.next = newNode; node.prev = newNode; size++; }
  • 8. private E remove(Node node) { if (node == head) { head = node.next; } else { node.prev.next = node.next; } if (node == tail) { tail = node.prev; } else { node.next.prev = node.prev; } size--; return node.element; } @Override public String toString() { StringBuilder sb = new StringBuilder("["); for (Node node = head; node != null; node = node.next) { if (node != head) { sb.append(", "); } sb.append(node.element); } sb.append("]"); return sb.toString(); } public void remove(Car lastCar) { // TODO Auto-generated method stub } } ( import java. io. BufferedReader;