Question

In: Accounting

You are running a Book shop where you are keeping inventory for all the books. Design...

You are running a Book shop where you are keeping inventory for all the books.
Design a program with the following interface using javafx scene builder, File IO and ArrayList class.
Following GUI is just an example choose different color, design and font for your GUI interface.

Write program which allows you to enter book name, author, price of each book and number of books in stock of the book through textboxes and store it in arraylist.
Write button reads value from arraylist and write into file as per follows:
javaprogramming,danialliang,99.50,10
database,johny,50.45,6
javaprogramming,tony,80.30

You can choose any different names to store in file.

Also design and write code for add, save, exit, next, previous and edit button as discussed in class.

Design display button which read information from file and display information in text area as per following fig. You can calculate TotalPrice=price of book * number of books in stock.

Design search button as per following fig. Enter the book name you want to search in text field. Search button compare the name you enter in textfield and the book name that stored in file.

If both names are same than print the entire record in text area including Name, Author, Price, Quantity and TotalPrice

If names does not match than print message like match not found in text area.

Use following code to write Book.java class

public class Book
{
private String bookname,author;
private int quantity;
private double price;

public Book() {
}

public Book(String bookname, String author, int quantity, double price) {
this.bookname = bookname;
this.author = author;
this.quantity = quantity;
this.price = price;
}

public String getBookname() {
return bookname;
}

public String getAuthor() {
return author;
}

public int getQuantity() {
return quantity;
}

public double getPrice() {
return price;
}

public void setBookname(String bookname) {
this.bookname = bookname;
}

public void setAuthor(String author) {
this.author = author;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public void setPrice(double price) {
this.price = price;
}   
}

Solutions

Expert Solution

////////////////////////////// javafx project , bookgui package


package bookgui;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
*
* @author DEBOJYOTY CHAKRAVORT
*/
public class BookGUI extends Application {
  
private int i;
  
@Override
public void start(Stage primaryStage) throws FileNotFoundException, IOException {
ArrayList<Book> bookLst=new ArrayList<Book>();
  
i=0;
  
  
TextArea textArea = new TextArea();
textArea.setPrefHeight(200);
textArea.setPrefWidth(200);
  
  
Label b1 = new Label("Book Name: ");
Label b2 = new Label("Author Name: ");
Label b3 = new Label("Price: ");
Label b4 = new Label("Quantity: ");
  
Label b1_ = new Label("Book Name: ");
Label b2_ = new Label("Author Name: ");
Label b3_ = new Label("Price: ");
Label b4_ = new Label("Quantity: ");
  
Label bd1 = new Label("");
Label bd2 = new Label("");
Label bd3 = new Label("");
Label bd4 = new Label("");
  
  
TextField bt1 = new TextField();
TextField bt2 = new TextField();
TextField bt3 = new TextField();
TextField bt4 = new TextField();
  
  
Button add = new Button();
add.setText("Add");
add.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {

Book b=new Book();
b.setBookname(bt1.getText());
b.setAuthor(bt2.getText());
b.setPrice(Double.parseDouble(bt3.getText()));
b.setQuantity(Integer.parseInt(bt4.getText()));
  
bookLst.add(b);
  
String s="";
for(int a=0;a<bookLst.size();a++){
Book b1=bookLst.get(a);
  
s+="Data "+(a+1);
s+="\nName: "+b1.getBookname();
s+="\nAuthor: "+b1.getAuthor();
s+="\nUnit Price: $"+b1.getPrice();
s+="\nQty: "+b1.getQuantity();
s+="\nTotal: $"+(b1.getPrice()*b1.getQuantity())+"\n\n";
}
  
textArea.setText(s);
  
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Information");
alert.setHeaderText("Data Adding");
alert.setContentText(bt1.getText()+"\n"+bt2.getText()+"\n"+bt3.getText()+"\n"+bt4.getText()+"\n"+"\n\nData Added succesfully");
alert.show();
}
});
  
Button exit = new Button();
exit.setText("Exit");
exit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.exit(0);
}
});
  
  
Button save = new Button();
save.setText("Save");
save.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
  
bookLst.get(i).setBookname(bt1.getText());
bookLst.get(i).setAuthor(bt2.getText());
bookLst.get(i).setPrice(Double.parseDouble(bt3.getText()));
bookLst.get(i).setQuantity(Integer.parseInt(bt4.getText()));
  
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Information");
alert.setHeaderText("Data Savinging");
alert.setContentText(bt1.getText()+"\n"+bt2.getText()+"\n"+bt3.getText()+"\n"+bt4.getText()+"\n"+"\n\nData Saved succesfully");
alert.show();
  
  
String s="";
for(int a=0;a<bookLst.size();a++){
Book b=bookLst.get(a);
  
s+="Data "+(a+1);
s+="\nName: "+b.getBookname();
s+="\nAuthor: "+b.getAuthor();
s+="\nUnit Price: $"+b.getPrice();
s+="\nQty: "+b.getQuantity();
s+="\nTotal: $"+(b.getPrice()*b.getQuantity())+"\n\n";
}
  
textArea.setText(s);
  
}
  
  
});
  
  
Pane pane1 = new Pane();
GridPane gp1 = new GridPane();
gp1.add(b1,0,0);
gp1.add(bt1,1,0);
gp1.add(b2,0,1);
gp1.add(bt2,1,1);
gp1.add(b3,0,2);
gp1.add(bt3,1,2);
gp1.add(b4,0,3);
gp1.add(bt4,1,3);
  
gp1.add(new Label(),0,4);
gp1.add(new Label(),1,4);
gp1.add(new Label(),2,4);
  
gp1.add(add,0,5);
gp1.add(save,1,5);
gp1.add(exit,2,5);
  
  
  
pane1.getChildren().add(gp1);
  
Button next = new Button();
next.setText("Next");
next.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {   
int s=i;
if(s<bookLst.size()-1){
s++;
}
i=s;
  
Book b=bookLst.get(s);
  
bd1.setText(b.getBookname());
bd2.setText(b.getAuthor());
bd3.setText(Double.toString(b.getPrice()));
bd4.setText(Integer.toString(b.getQuantity()));
  
  
}
});
  
  
Button prev = new Button();
prev.setText("Previous");
prev.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int s=i;
  
if(s>0){
s--;
}
  
i=s;
  
Book b=bookLst.get(s);
  
bd1.setText(b.getBookname());
bd2.setText(b.getAuthor());
bd3.setText(Double.toString(b.getPrice()));
bd4.setText(Integer.toString(b.getQuantity()));
}
});
  
  
Button edit = new Button();
edit.setText("Edit");
edit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int s=i;
  
Book b=bookLst.get(s);
  
bt1.setText(b.getBookname());
bt2.setText(b.getAuthor());
bt3.setText(Double.toString(b.getPrice()));
bt4.setText(Integer.toString(b.getQuantity()));
  
}
});
  
  
Pane pane2 = new Pane();
GridPane gp2 = new GridPane();
gp2.add(b1_, 0, 0);
gp2.add(bd1, 1, 0);
gp2.add(b2_, 0, 1);
gp2.add(bd2, 1, 1);
gp2.add(b3_, 0, 2);
gp2.add(bd3, 1, 2);
gp2.add(b4_, 0, 3);
gp2.add(bd4, 1, 3);
  
gp2.add(new Label(), 0, 4);
gp2.add(new Label(), 1, 4);
gp2.add(new Label(), 2, 4);
  
gp2.add(prev, 0, 5);
gp2.add(next, 1, 5);
gp2.add(edit, 2, 5);
  
pane2.getChildren().add(gp2);
  
  
  
  
Button upload = new Button();
upload.setText("Upload and Display");
upload.setOnAction(new EventHandler<ActionEvent>() {
  
@Override
public void handle(ActionEvent event) {
FileReader fr=null;
try {
fr = new FileReader("books.txt");
BufferedReader br=new BufferedReader(fr);
String line="";
  
while((line=br.readLine())!=null){
String [] splt=line.split(",");
Book book=new Book();
book.setBookname(splt[0]);
book.setAuthor(splt[1]);
book.setPrice(Double.parseDouble(splt[2]));
book.setQuantity(Integer.parseInt(splt[3]));
  
bookLst.add(book);
}
  
String s="";
for(int a=0;a<bookLst.size();a++){
Book b=bookLst.get(a);
  
s+="Data "+(a+1);
s+="\nName: "+b.getBookname();
s+="\nAuthor: "+b.getAuthor();
s+="\nUnit Price: $"+b.getPrice();
s+="\nQty: "+b.getQuantity();
s+="\nTotal: $"+(b.getPrice()*b.getQuantity())+"\n\n";
}
  
textArea.setText(s);
  
}
catch (IOException ex) {
  
}
}
});
  
  
  
  
Pane pane3 = new Pane();
GridPane gp3 = new GridPane();
gp3.add(upload,0,0);
gp3.add(new Label(),0,1);
gp3.add(textArea,0,2);
  
pane3.getChildren().add(gp3);
  
  
  
GridPane gridPane = new GridPane();
gridPane.setMinSize(680, 230);
gridPane.add(pane1, 0, 1);
gridPane.add(pane2, 1, 1);
gridPane.add(pane3, 2, 1);
gridPane.setHgap(30);
  
StackPane root = new StackPane();
root.getChildren().add(gridPane);
  
Scene scene = new Scene(root, 740, 280);
  
primaryStage.setTitle("Book List");
primaryStage.setScene(scene);
primaryStage.show();
}

  
  
  
  
  
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
  
}
/////////////////////////////////////////////////

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bookgui;

public class Book
{
private String bookname,author;
private int quantity;
private double price;

public Book() {
}

public Book(String bookname, String author, int quantity, double price) {
this.bookname = bookname;
this.author = author;
this.quantity = quantity;
this.price = price;
}

public String getBookname() {
return bookname;
}

public String getAuthor() {
return author;
}

public int getQuantity() {
return quantity;
}

public double getPrice() {
return price;
}

public void setBookname(String bookname) {
this.bookname = bookname;
}

public void setAuthor(String author) {
this.author = author;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public void setPrice(double price) {
this.price = price;
}   
}
//////////////////////////////////


Related Solutions

Today BandN book stores is currently running a deal on e-books. Customers will receive a 15%...
Today BandN book stores is currently running a deal on e-books. Customers will receive a 15% discount off their entire order. Customers who buy 20 or more e-books will receive 20% off instead. Each book costs a flat $8.99. Write a C++ program that will calculate the final cost of your order, using functions. Global variables are not allowed unless they are constant. Information should be passed with parameters. Your main function should not do any of the tasks in...
Suppose, you are running a small business and want to open a bank account for keeping...
Suppose, you are running a small business and want to open a bank account for keeping your extra cash in it. Visit any nearby bank and describe in detail the different types of bank accounts opened in the Pakistani banks?
Vail Book Mart sells books and other supplies to students in a state where the sales...
Vail Book Mart sells books and other supplies to students in a state where the sales tax rate is 8 percent. Vail Book Mart engaged in the following transactions for Year 1. Sales tax of 8 percent is collected on all sales. Book sales, not including sales tax, for Year 1 amounted to $274,000 cash. Cash sales of miscellaneous items in Year 1 were $147,000, not including tax. Cost of goods sold was $209,000 for the year. Paid $131,000 in...
Vail Book Mart sells books and other supplies to students in a state where the sales...
Vail Book Mart sells books and other supplies to students in a state where the sales tax rate is 8 percent. Vail Book Mart engaged in the following transactions for Year 1. Sales tax of 8 percent is collected on all sales. Book sales, not including sales tax, for Year 1 amounted to $277,000 cash. Cash sales of miscellaneous items in Year 1 were $146,000, not including tax. Cost of goods sold was $212,000 for the year. Paid $129,000 in...
The Oriole Publications Textbook Company sells all of its books for $100 per book, and it...
The Oriole Publications Textbook Company sells all of its books for $100 per book, and it currently costs $50 in variable costs to produce each text. The fixed costs, which include depreciation and amortization for the firm, are currently $2 million per year. Management is considering changing the firm’s production technology, which will increase the fixed costs for the firm by 46 percent but decrease the variable costs per unit by 46 percent. If management expects to sell 45,000 books...
The Wildhorse Publications Textbook Company sells all of its books for $100 per book, and it...
The Wildhorse Publications Textbook Company sells all of its books for $100 per book, and it currently costs $50 in variable costs to produce each text. The fixed costs, which include depreciation and amortization for the firm, are currently $2 million per year. Management is considering changing the firm’s production technology, which will increase the fixed costs for the firm by 36 percent but decrease the variable costs per unit by 36 percent. If management expects to sell 45,000 books...
Jane Allen is a sole trader running a small chemist shop. She provides you with the...
Jane Allen is a sole trader running a small chemist shop. She provides you with the following balances from her ledger accounts at 30 June, 2020. The adjusting entries have already been completed and the list of accounts is in no particular order. Account title 2020 J Allen, Capital 180 000 Office Equipment 21 500 Cost of Goods Sold 124 870 Accumulated Depn – Office Equip 5 900 Salaries Expense Payable 1 240 Inventory 95 412 Inventory Shortage Expense 160...
Question 2: Double entry book-keeping and simple accounts preparation You are given a list of transactions...
Question 2: Double entry book-keeping and simple accounts preparation You are given a list of transactions of ‘Happy T-shirt’ below. Transaction 1: You are opening a new business selling printed T-shirts called ‘Happy T-shirt’. You buy t-shirts and print before selling them. You invest £5,000 and borrow £5,000 to start your company. What are the dual effects on the accounting equation? Transaction 2: After you form your company, you need to buy equipment to print the t-shirts. You purchase £2,000...
Keeping in mind all that you have read in this course and your personal and professional...
Keeping in mind all that you have read in this course and your personal and professional experience, what challenges do you believe HR specialists in the recruitment and selection field face in the current hiring climate?
Mira’s Book distributes books to retail stores and extends credit terms of 2/15 n/30 to all...
Mira’s Book distributes books to retail stores and extends credit terms of 2/15 n/30 to all of its customers. At the end of May, Mira’s inventory consisted of 100 books purchased for @ of $18 total of $1,800. During June, the following merchandising transactions occurred.And they are following periodic inventory system. June 1 Purchased 32 books on account for @ of $50 total of $1,600 from Bondhu Publishers, FOB destination, terms 2/4, n/30. The appropriate party also made a cash...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT