
Due Date: 11:59 pm, Sunday 28 August 2022
Objectives: To design and implement an application in JavaFX and to use SQL and JDBC for data persistence.
Introduction
The aim of the assignment is to create an application to maintain a collection of products stored in your warehouse. The products and a list of items are stored in a MySQL database.
The system consists of the following main classes:
- • Product
- Item
- • WarehouseDSC
- WarehouseFX
The Product class represents a Product item stored in the warehouse. The complete class code is provided. As can be seen from the provided code, the class has the following attributes:
- id: the unique identifier of a product.
- item: an instance of Item class.
- Item class, (complete code also provided) has the following attributes
- name: the name of an item from which you can pick to make a Product object
- expires: whether or not this item can expire
- Item class, (complete code also provided) has the following attributes
- date: the date the Product item was added to the warehouse.
- quantity: quantity of such Product item added to the warehouse at the same time.
- section: which section of the warehouse is this Product stored.
The id attribute of a Product is of type int and is actually automatically generated by the database, as can be seen in the SQL script.
The second class, Item, has a one to one mapping with the Product where Product class has one (and only one) instance of Item.
The third class, WarehouseDSC, is the data source controller. A skeleton of this class is provided.
The fourth class, WarehouseFX, provide the graphical user interface for the users to interact with the system. This class is implemented in JavaFX. A skeleton of this class is provided.
An SQL script is also provided to create the tables. Note:
- 2 tables will be created upon execution of the script: a Product table and an item table.
- Sample records will also be added to these 2 tables
Task 1
Implement the WarehouseDSC class. A skeleton of the class is provided, which indicates the methods that you are required to implement. Relevant database connectivity measure must be coded in (DriverManager, Connection, Statement, PreparedStatement) and the implementation for methods stubs require you to connect to a database/table and perform the required task – the queries (String variable) for each of the method will be provided in the code.
NOTE: Carefully read the comments provided throughout the skeleton class – they provide useful hints on how to proceed with each method stubs/tasks. You are required to implement each part labeled with /* TODO 1-xx – TO COMPLETE ****************************************
Task 2
Implement the WarehouseFX class. When the system is started, a screen similar to the one shown in Figure 1 is displayed. Your WarehouseFX class should create an instance of WarehouseDSC class and use that object instance methods to perform the create, read, update, delete (CRUD) operations described below;
NOTE: Carefully read the comments provided throughout the skeleton class – they provide useful hints on how to proceed with each method stubs/tasks. You are required to implement each part labeled with
/* TODO 2-xx – TO COMPLETE ****************************************
Figure 1 – Screen displayed by WarehouseFX
Describing the User Interface Flow/Requirements
Figure 1 shows the overall User Interface of the application you are required to build; Let us discuss each section;
Figure 1.1 – “Filter By:” ChoiceBox in action Figure 1.1 shows the following interactive controls:
- A TextField – this allows the user to filter the TableView data
- A ChoiceBox – this allows the user to select which Column of the TableView to use as filter target o When ITEM option (default selection) is selected, the TextField filter will target the values in the TableView “Item” column
- When SECTION option is selected, the TextField filter will target the values in the TableView “Section” column o When BOUGHT_DAYS_AGO is
selected, it does the following:
- Enables the “Show Expire Only” CheckBoxSets the TextField filter to the TableView “Bought” column (only it’s numerical value), listing all Product s bought on the filtered value days and prior
- A CheckBox – this is currently disabled; this control is enabled when the “Filter By:”
BOUGHT_DAYS_AGO option is selected.
NOTE: the Product class has an attribute of type Item class; Item class has a boolean expires attribute; The “Show Expire Only” Checkbox, when selected, will also filter out those Product elements having an item with attribute expires set to true;
Figure 1.2 – BOUGHT_DAYS AGO filter, “Show Expire Figure 1.3 – BOUGHT_DAYS AGO filter, “Show Expire Only” not selected Only” selected
The next control is the TableView. The TableView displays the Product s in the collection, one Product per row. Each row of the TableView is selectable; In order to use the “UPDATE ONE” or the “DELETE” button, the relevant TableView row (a product ) must be selected by the user;
Adding a new product :
Clicking the “ADD” button reveals a hidden container (see Figure 2)
Figure 2 – Adding a Product
You are then provided with 3 controls:
- A ComboBox – lists all items stored – each item is an instance of Item class; For simplicity, we are displaying the toString() result of each item instance as value of the ComboBox list. (see Figure
2.1)
- A ChoiceBox – listing the possible sections in the warehouse; the section values is defined as an enum
in WarehouseDSC class. (See Figure 2.2)
- A TextField – user input for quantity of selected item the user is about to add to the warehouse.
Figure 2.1 – the “Item” ComboBox listing Figure 2.2 – the “Section” ChoiceBox listin
After selecting/entering some Product information in the add controls, click the SAVE button, to create a new Product entry (see Figure 2.3 and 2.4)
Figure 2.3 – entering new Product information Figure 2.4 – saved new product , listed in the TableView
Update One Product
The UPDATE ONE button decreases the quantity of a selected Product in the TableView. If the selected Product is already one it will prompt a relevant error message.
Figure 2.5 – try to UPDATE ONE Product with quantity = 1 Figure 2.6 – successfully UPDATE ONE action on Product
(id: 33) with quantity = 3, now quantity = 2
Delete (one) Product
The DELETE button prompts user with a confirmation message, and if user accepts (clicks OK button) deletes the selected product .
Figure 2.5 – DELETE selected product , user prompted for Figure 2.6 – successful DELETE of Product (id: 19) confirmation
Use adequate means of alerting users of relevant events
Make sure you add a notification mechanism (example: Alert boxes) to
- Prompt user before executing a critical action (an add, an update or a delete)
- Inform user when an error has occurred; see Exception Handling for more requirements on error handling
Exception Handling
Make sure you add the exception handling code so that whenever an exception occurs, the program displays an alert which shows a brief message about the exception.
Implementation Suggestion
You are encouraged to implement Assignment 1 in the following order:
- In the JavaFX UI class (WarehouseFX), code the control and container elements;
- Code the data source controller (WarehouseDSC), all the required interaction with the database, the methods needed for the UI class (WarehouseFX) to interact with this data source controller
- Implement a main method in your WarehouseDSC class to facilitate testing all the needed required methods; see your lab sample solution for some examples.
- Go back to the UI class (WarehouseFX)
- add Lambda function code stubs for the Buttons setOnAction methods;
- add the relevant Alert boxes
- Test the overall system thoroughly, making sure it compiles on sql
There are two approaches:
- In the JavaFX GUI class (WarehouseFX), this is a commented-out section that includes the code for creating a list of products. If you use this commented out section for the TableView you can get the control
and container elements done. Add Lambda function code stubs for the Buttons setOnAction methods and add the relevant Alert boxes. Then later when you have done the WarehouseDSC.java you can replace the hard coded products list with the list that comes back from the DSC. The advantage of this is that you can start earlier, and don’t have to wait for the SQL lectures.
- Start with the WarehouseDSC.java, this has all the required interaction with the database, and includes all methods needed for the UI class (WarehouseFX). Examine the main method in your WarehouseDSC class and test all the needed required methods. Then Work on the WarehouseFX.java.
Files Provided
- Item.java
- Product.java
- WarehouseDSC.java
- WarehouseFX.java
- CreateDatabaseScript.sql

Get expert help for To design and implement an application in JavaFX and to use SQL and JDBC for data persistence and many more. 24X7 help, plag free solution. Order online now!