Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using JavaFX how do I get my datasetbook to run with the following? Book: public class Book { private String author; private String title; private

Using JavaFX how do I get my datasetbook to run with the following?

Book:

public class Book { private String author; private String title; private int pages;

public Book(String auth, String titl, int pag) { author = auth; title = titl; pages = pag; }

@Override public String toString() { return "Book [author=" + author + ", title=" + title + ", pages=" + pages + "]"; }

public String getAuthor() { return author; }

public String getTitle() { return title; }

public int getPages() { return pages; }

@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Book other = (Book) obj; if (author == null) { if (other.author != null) return false; } else if (!author.equals(other.author)) return false; if (pages != other.pages) return false; if (title == null) { if (other.title != null) return false; } else if (!title.equals(other.title)) return false; return true; }

}

DataSetBook:

import java.util.ArrayList; import java.util.Arrays;

/** * A simple store for Book objects. * * @author student * */ public class DataSetBook extends ArrayList { /** * Default constructor */ public DataSetBook() { } /** * Add a Book to the store * * @param objToAdd * * @return true if the element was added to the collection, false otherwise */ public boolean add(Book objToAdd) { return super.add(objToAdd); } /** * The number of Books currently in the store * * @return number of Book objects */ public int size() { return super.size(); } /** * Determine the Book with the fewest pages * * @return null if the store is empty. The book with the fewest pages * otherwise. If more than one book has the fewest number of pages, * the first one is returned. */ public Book getMin() { if (super.isEmpty()) { return null; } Book mEle = super.get(0); for (int i = 1; i < super.size(); i++) { if (mEle.getPages() > (super.get(i).getPages())) { mEle = super.get(i); } } return mEle; }

/** * Determine the Book with the most pages * * @return null if the store is empty. The book with the most pages * otherwise. If more than one book has the most number of pages, * the first one is returned. */ public Book getMax() { if (super.isEmpty()) { return null; } Book mEle = super.get(0); for (int i = 1; i < super.size(); i++) { if (mEle.getPages() < (super.get(i).getPages())) { mEle = super.get(i); } } return mEle; }

/** * A String representation of the store. * * @return A String containing the number of books in the store, * the minimum book, the largest book, and * the contents of the entire store. */ @Override public String toString() { return "DataSetBook [ size()=" + size() + " getMin()=" + getMin() + " getMax()=" + getMax() + " Books= " + Arrays.toString(super.toArray()) + "]"; }

}

import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.stage.Stage;

public class Handler extends Application { public void start(Stage stage) { Label author= new Label("Author");//creating labels and textfields TextField textField= new TextField();

Label title= new Label("Title"); TextField textField2= new TextField(); Label pages= new Label("Pages"); TextField textField3= new TextField(); Button button= new Button("Make a New Book");//creating button button.setAlignment(Pos.TOP_RIGHT); HBox hb = new HBox(); hb.getChildren().addAll(author, textField, title, textField2, pages, textField3, button); hb.setSpacing(10); BorderPane borderPane= new BorderPane(); borderPane.setTop(hb); BorderPane.setAlignment(hb, Pos.TOP_CENTER);

Scene scene= new Scene(borderPane, 800, 500); stage.setTitle("A Simple Book Store"); stage.setScene(scene); stage.show();

} }

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

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions

Question

What does the start( ) method defined by Thread do?

Answered: 1 week ago

Question

2. What is the impact of information systems on organizations?

Answered: 1 week ago

Question

Evaluate the impact of technology on HR employee services.

Answered: 1 week ago