Please help me with this project. In project one, we created five classes(BikePa
ID: 3725238 • Letter: P
Question
Please help me with this project. In project one, we created five classes(BikePart.java, Inventory.java, wareHouse.java, processCommand.java, and main.java). I am going to put all the five classes here to give more inforemation about this project. Based on the five classes, I need to have another class(wareHouseFactory) which has an ArrayList<wareHouse>. I also need to have an view(FXML) and controller class. Please provide the solution for the controller calss as well. The following is an example of test cases for the sell command.
Setup Prior to Running the Test Case
Program is running with a main warehouse and two sales vans: van1 and van2 .
The van1 sales van has 10 saddle bike parts: saddle,12345678905,50.00,40.00,true
The van2 sales van does not have any saddle bike parts.
The van2 sales van has 5 wheel bike parts: wheel,12345678910,100.00,85.00,false
Test 1: Sell saddle from van1 sales van, saddle is on sale
Inputs
name of product to sell - saddle, name of sales van from which to sell - van1
Expected Results
Display shows saddle, cost is 40.00 (sales price), and current date
The number of saddles in gusty sales van is now 9
Test 2: Sell saddle from van2 sales van, saddle is not on van
Inputs
name of product to sell - saddle, name of sales van from which to sell - van2
Expected Results
Part not found
Test 1: Sell wheel from van2 sales van, wheel is not on sale
Inputs
name of product to sell - wheel, name of sales van from which to sell - van2
Expected Results
Display shows wheel, cost is 100.00 (regular price), and current date
The number of wheels in van2 sales van is now 4
Introduction for this project:
Introduction
You are a programmer working for Bicycle Parts Distributorship. BPD has a warehouse full of
bicycle parts. The warehouse parts and database are as described in Project 1. In this increment
of the project BPD has purchased vans and hired sales personnel who drive the vans. The sales
personnel load their vans with bicycle parts, which they sell to bicycle shops located throughout
the sales district. Each sales van is its own warehouse that has inventory. When a sales van is
loaded with parts, the inventory in the main warehouse is decremented and the inventory in the
sales van is incremented. Sometimes, a sales associate does not want to drive to the main
warehouse to get a few parts. In these cases, sales associates agree to meet and move parts from
one sales van warehouse to another.
Warehouse Parts Inventory Update
The warehouse parts inventory update shall be done by processing an inventory delivery file just
like Project 1.
Sales Van Parts Inventory Update from Main Warehouse
When a sales associate visits the warehouse to load their van with parts, the sales associate
arrives with a sales van delivery file that describes the bicycle parts that are to be moved from
the main warehouse onto their van. The file consists of a sequence of comma-separated
lines. The first line contains the name of the main warehouse followed by the name of a
destination van, where parts are moved from the main warehouse to the destination. Each of the
remaining lines contains the name of the bicycle part and the quantity that is to be moved from
the main warehouse into the sales van warehouse. The following is an example.
mainWarehouse,salesVanC
WTB_saddle,4
26inTube,10
seatPost,2
Sales Van Parts Inventory Update from a Sales Van
When sales associate A meets with a sales associate B to get parts, sales associate A arrives with
a sales van delivery file that describes the bicycle parts that are to be moved from sales associate
B’s van into sales associate A’s van. The file consists of a sequence of comma-separated
lines. The first line contains the name of the source van followed by the name of a destination
van, where parts are moved from the source to the destination. Each of the remaining lines
contains the name of the bicycle part and the quantity that is to be moved from the source van to
the destination van. The following is an example.
salesVanA,salesVanB
WTB_saddle,4
26inTube,10
seatPost,2
carbonHandleBars42cm,25
When a sales van delivery file is processed in this case, the inventory in both the salesperson A’s
delivery van warehouse and salesperson B’s delivery van warehouse are updated.
NOTE1: Read this specification carefully. You must implement the program as described.
NOTE2: The Bicycle Parts Distributorship project specifications use the term database as a
general description of the underlying data that must be persistent across executions of your
program. To satisfy the persistent requirement, your database will have to be a file (or files) that
your program reads/writes. You do not have to create an SQL or NOSQL database.
Program Functional Requirements( The first 9 requirements are done by the five classes that I provide below. Please do the code to satisfy the last three requirments. Thank you very much.)
Your program shall accomplish the following. NOTE: Requirements 1 through 9 are identical
from Project 1; however, some implementation details such as filenames have been removed.
1. Your program shall have a warehouse database. The first time your program runs the
warehouse database shall be empty or nonexistent.
2. Your program shall read the warehouse database upon starting. This shall establish the
initial inventory in your internal data structures.
3. Your program shall write the internal data structures to the warehouse database upon
exiting. The inventory in your internal data structures shall be saved such that upon
running your program again, it starts with the same data as it ended with.
4. Your program shall read inventory delivery files (e.g., inventory.txt) as input by the
user. Reading inventory delivery files updates the data in your internal data structures as
follows.
a) If the bicycle part is not a member of your internal data structure, the bicycle part
is added.
b) If the bicycle part is is in your internal data structure, the list price is updated, the
sales price is updated, the on sale indicator is updated, and the quantity is added to
the current quantity on hand.
5. Your program shall show the bicycle part information by name.
6. Your program shall sell a bicycle part by part number from a warehouse. The sell shall
allow the user to specify the warehouse. When a bicycle part is sold, you shall do the
following for the specified warehouse.
a) Display the part name, the part cost, which will be either the list price of sale
price.
b) Display the time the part was sold.
c) Decrement the quantity.
7. Your program shall allow a new part to be entered interactively.
8. Your program shall display all parts in alphabetical order. This display shall show all
inventory attributes (name, number, list price, sale price, on-sale indicator, quantity). The
display alphabetical order shall allow specifying a particular warehouse as follows.
a) The total collection of warehouses
b) The main warehouse
c) Each individual sales van warehouse
9. Your program shall display all parts in part number order. This display shall show all
inventory attributes (name, number, list price, sale price, on-sale indicator, quantity). The
display part number order shall allow specifying a particular warehouse as follows.
a) The total collection of warehouses
b) The main warehouse
c) Each individual sales van warehouse
10. Your program shall allow the user to add a sales van to the fleet.
11. Your program shall allow a sales associate to move inventory from the main warehouse
into the sales van warehouse.
12. Your program shall allow a sales associate to move inventory from another sales van
warehouse into its sales van warehouse.
Object-oriented Requirements
1. Your program shall define and use a Java Interface as part of its solution.
2. Your program shall define and use inheritance as part of its solution.
User Interface Requirements
1. Your program shall have a JavaFX Graphical User Interface. The layout of the GUI
panels is your design, but I recommend you create a simple interface.
// BikePart class.
// Inventory class
//warehouse class
//ProcessCommand class
//Main class
new capabilities described in this project description. NOTE1: Read this specification carefully. You must implement the program as describe questions as needed for clarification. d. Ask NOTE2: The Bicycle Parts Distributorship project specifications use the term database as a general description of the underlying data that must be persistent across executions of your program. To satisfy the persistent requirement, your database will have to be a file (or fil your program reads/writes. You do not have to create an SQL or NOSQL database. es) that Introduction You are a programmer working for Bicycle Parts Distributorship. BPD has a warehouse full of bicycle parts. The warehouse parts and database are as described in Project 1. In this in of the project BPD has purchased vans and hired sales personnel who drive the vans. The sales personnel load their vans with bicycle parts, which they sell to bicycle shop the sales district. Each sales van is its own warehouse that has inventory. When a sales van i loaded with parts, the inventory in the main wa sales van is increment warehouse to get a few parts. In these cases, sales associates agree to meet and move parts from one sales van warehouse to another. s located throughout rehouse is decremented and the inventory in the ed. Sometimes, a sales associate does not want to drive to the main Warehouse Parts Inventory Update The warehouse parts inventory update shall be done by processing an inventory delivery file j like Project 1. ust Sales Van Parts Inventory Update from Main Warehouse When arrives with a sales van delivery file that describes the bicycle parts that are to be moved from the main warahouse onto their van. The file consists of a sequence of comma-separated lines. a sales associate visits the warehouse to load their van with parts, the sales associateExplanation / Answer
Reader.java
package pkg;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Reader {
private static void readInventoryFile(File file) {
String originWarehouse = "";
String destinationWarehouse = "";
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line = bufferedReader.readLine();
if (line.split(",")[0].equals("mainWarehouse")) {
originWarehouse = "mainWarehouse";
if (WarehouseFactory.getInstance().getWarehouseByName(line.split(",")[1]) != null) {
destinationWarehouse = line.split(",")[1];
} else {
OutputBuffer.getInstance().add("The Warehouse " + line.split(",")[1] + " does not exist. Please add it and try again.");
return;
}
} else {
if (WarehouseFactory.getInstance().getWarehouseByName(line.split(",")[0]) != null) {
originWarehouse = line.split(",")[0];
} else {
OutputBuffer.getInstance().add("The Warehouse " + line.split(",")[0] + " does not exist. Please add it and try again.");
return;
}
if (WarehouseFactory.getInstance().getWarehouseByName(line.split(",")[1]) != null) {
destinationWarehouse = line.split(",")[1];
} else {
OutputBuffer.getInstance().add("The Warehouse " + line.split(",")[1] + " does not exist. Please add it and try again.");
return;
}
}
if (originWarehouse.equals("mainWarehouse")) {
while ((line = bufferedReader.readLine()) != null) {
String partName = line.split(",")[0];
Long quantity = Long.parseLong(line.split(",")[1]);
if (quantity > PartList.getInstance().getPartByName(partName).getQuantity()) {
OutputBuffer.getInstance().add("Not enough parts available.");
return;
}
try{
WarehouseFactory.getInstance().getWarehouseByName(destinationWarehouse).getPartList().getPartByName(partName);
} catch (Exception e) {
WarehouseFactory.getInstance().getWarehouseByName(destinationWarehouse).addPart(partName, quantity);
}
}
} else {
if (!originWarehouse.equals("") && !destinationWarehouse.equals("")) {
while ((line = bufferedReader.readLine()) != null) {
readInventoryLine(line, originWarehouse, destinationWarehouse);
}
}
}
fileReader.close();
OutputBuffer.getInstance().add(WarehouseFactory.getInstance().getWarehouseByName(destinationWarehouse).getPartList().getStrings()[0]);
} catch (IOException e) {
OutputBuffer.getInstance().add("Failed to read file.");
return;
}
}
private static void readInventoryLine(String line, String origin, String dest) {
String partName = null;
Long quantity = null;
boolean addToDB = true;
try {
partName = line.split(",")[0];
quantity = Long.parseLong(line.split(",")[1]);
} catch (Exception e) {
OutputBuffer.getInstance().add("Failed to parse input.");
addToDB = false;
} finally {
if (addToDB) {
if (WarehouseFactory.getInstance().getWarehouseByName(origin).getPartList().getPartByName(partName).decrement(quantity)) {
if (WarehouseFactory.getInstance().getWarehouseByName(dest).getPartList().getPartByName(partName) != null) {
WarehouseFactory.getInstance().getWarehouseByName(dest).addPart(partName, quantity);
} else {
WarehouseFactory.getInstance().getWarehouseByName(dest).getPartList().getPartByName(partName).increment(quantity);
}
} else {
OutputBuffer.getInstance().add("Insufficient amount of parts.");
}
}
}
}
public static void readPartLine(String line) {
String partName = null;
Long partNumber = null;
Double listPrice = null;
Double salePrice = null;
boolean> Long quantity = null;
boolean addToDB = true;
try {
partName = line.split(",")[0];
partNumber = Long.parseLong(line.split(",")[1]);
listPrice = Double.parseDouble(line.split(",")[2]);
salePrice = Double.parseDouble(line.split(",")[3]);
> quantity = Long.parseLong(line.split(",")[5]);
} catch (Exception e) {
OutputBuffer.getInstance().add("Failed to parse input.");
addToDB = false;
} finally {
if (addToDB) {
if (PartList.getInstance().getPartByNumber(partNumber) != null) {
PartList.getInstance().getPartByNumber(partNumber).setListPrice(listPrice);
PartList.getInstance().getPartByNumber(partNumber).setSalePrice(salePrice);
PartList.getInstance().getPartByNumber(partNumber).setOnSale(onSale);
PartList.getInstance().getPartByNumber(partNumber).increment(quantity);
} else {
PartList.getInstance().add(new Part(partName, partNumber, listPrice, salePrice, onSale, quantity));
}
}
}
}
public static void readFile(File file) {
String testline = "";
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
testline = bufferedReader.readLine();
}catch (Exception e) {
System.out.println("fail");
}
if (testline.split(",").length == 2) {
readInventoryFile(file);
OutputBuffer.getInstance().add("Successfully read file.");
} else {
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
readPartLine(line);
}
fileReader.close();
OutputBuffer.getInstance().add("Successfully read file.");
} catch (IOException e) {
OutputBuffer.getInstance().add("Failed to read file.");
return;
}
}
}
}
WarehouseFactory.java
package pkg;
import java.util.*;
public class WarehouseFactory {
private static WarehouseFactory ourInstance = new WarehouseFactory();
private static ArrayList<Warehouse> warehouseList = new ArrayList<Warehouse>();
public static synchronized WarehouseFactory getInstance() {
return ourInstance;
}
private WarehouseFactory() {
}
public void construct(boolean isVehicle, String name, WarehousePartList partList) {
if (isVehicle) {
this.warehouseList.add(new Vehicle(name, partList));
} else {
this.warehouseList.add(new Warehouse(name, partList));
}
}
public static String[] getStrings() {
String[] strings = new String[warehouseList.size()];
for (int i = 0; i < warehouseList.size(); i++) {
Warehouse warehouse = warehouseList.get(i);
if (warehouse instanceof Vehicle) {
strings[i] = "Vehicle:" + warehouse.getName();
} else {
strings[i] = "Warehouse:" + warehouse.getName();
}
}
return strings;
}
public static Warehouse getWarehouseByName(String name) {
for (Warehouse warehouse : getWarehouseList()) {
try {
if (warehouse.getName().equals(name)) {
return warehouse;
} else {
return null;
}
} catch (Exception e) {
return null;
}
}
return null;
}
public static ArrayList<Warehouse> getWarehouseList() {
return warehouseList;
}
public void add(Warehouse warehouse) {
warehouseList.add(warehouse);
}
}
OutputBuffer.java
package pkg;
public class OutputBuffer {
private static OutputBuffer ourInstance = new OutputBuffer();
private static String output = "";
public static OutputBuffer getInstance() {
return ourInstance;
}
private OutputBuffer() {
}
public void add(String s) {
this.output = this.output + (s + " ");
}
public String get() {
String ret = this.output;
clear();
return ret;
}
public void clear() {
this.output = "";
}
}
WarehousePartList.java
package pkg;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
public class WarehousePartList {
private HashMap<Long, Part> partListNumb = new HashMap<Long, Part>();
private HashMap<String, Part> partListName = new HashMap<String, Part>();
private ArrayList<Part> partListCurr = new ArrayList<Part>();
public WarehousePartList() {
}
public void add(Part part) {
this.partListNumb.put(part.getPartNumber(), part);
this.partListName.put(part.getPartName(), part);
this.partListCurr.add(part);
}
public void remove(Part part) {
this.partListNumb.remove(part.getPartNumber());
this.partListName.remove(part.getPartName());
this.partListCurr.remove(part);
}
public ArrayList<Part> getPartListCurr() {
return partListCurr;
}
public void sortByName() {
partListCurr.clear();
partListCurr = new ArrayList<Part>(partListName.values());
Comparator<? super Part> byName = Comparator.comparing(Part::getPartName);
Collections.sort(partListCurr, byName);
}
public void sortByNumber() {
partListCurr.clear();
partListCurr = new ArrayList<Part>(partListName.values());
Comparator<? super Part> byNumber = Comparator.comparing(Part::getPartNumber);
Collections.sort(partListCurr, byNumber);
}
public int size() {
return this.partListNumb.size();
}
public Part getPartByNumber(Long partNumber) {
return partListNumb.get(partNumber);
}
public Part getPartByName(String partName) {
return partListName.get(partName);
}
public String[] getStrings() {
String[] strings = new String[this.partListCurr.size()];
for (int i = 0; i < this.partListCurr.size(); i++) {
Part part = this.partListCurr.get(i);
strings[i] = part.getPartName() + part.getPartNumber() + part.getQuantity();
}
return strings;
}
public Part get(int i) {
if (this.partListCurr.size() == 0) {
this.partListCurr = new ArrayList<Part>(this.partListName.values());
}
return partListCurr.get(i);
}
}
Part.java
package pkg;
public class Part {
private String partName;
private Long partNumber;
private Double listPrice;
private Double salePrice;
private boolean onSale;
private Long quantity;
public Part(String partName, Long partNumber, Double listPrice, Double salePrice, boolean onSale, Long quantity) {
this.partName = partName;
this.partNumber = partNumber;
this.listPrice = listPrice;
this.salePrice = salePrice;
this.onSale = onSale;
this.quantity = quantity;
}
public String getPartName() {
return this.partName;
}
public Long getPartNumber() {
return this.partNumber;
}
public Double getListPrice() {
return this.listPrice;
}
public Double getSalePrice() {
return this.salePrice;
}
public boolean isOnSale() {
return this.onSale;
}
public Long getQuantity() {
return this.quantity;
}
public void setPartName(String partName) {
this.partName = partName;
}
public void setPartNumber(Long partNumber) {
this.partNumber = partNumber;
}
public void setListPrice(Double listPrice) {
this.listPrice = listPrice;
}
public void setSalePrice(Double salePrice) {
this.salePrice = salePrice;
}
public void setOnSale(boolean onSale) {
this.onSale = onSale;
}
public void setQuantity(Long quantity) {
this.quantity = quantity;
}
public boolean decrement() {
if(this.quantity > 0) {
this.quantity--;
return true;
}else {
return false;
}
}
public boolean decrement(Long amt) {
if(this.quantity > amt) {
this.quantity -= amt;
return true;
}else {
return false;
}
}
public void increment() {
this.quantity++;
}
public void increment(Long amt) {
this.quantity = this.quantity + amt;
}
public String prettyString() {
return "Part: " + this.partName + " " + this.partNumber + " $" + this.listPrice + " $" + this.salePrice + " Sale:" + this.onSale + " " + this.quantity;
}
}
Vehicle.java
package pkg;
public class Vehicle extends Warehouse {
public Vehicle(String name, WarehousePartList partList) {
super(name, partList);
}
}
PartList.java
//package pkg;
import java.util.*;
public class PartList {
private static PartList ourInstance = new PartList();
private static HashMap<Long, Part> partListNumb = new HashMap<Long, Part>();
private static HashMap<String, Part> partListName = new HashMap<String, Part>();
private static ArrayList<Part> partListCurr = new ArrayList<Part>();
public static synchronized PartList getInstance() {
return ourInstance;
}
public PartList() {
}
public void add(Part part) {
this.partListNumb.put(part.getPartNumber(), part);
this.partListName.put(part.getPartName(), part);
this.partListCurr.add(part);
}
public void remove(Part part) {
this.partListNumb.remove(part.getPartNumber());
this.partListName.remove(part.getPartName());
this.partListCurr.remove(part);
}
public ArrayList<Part> getPartListCurr() {
return partListCurr;
}
public void sortByName() {
partListCurr.clear();
partListCurr = new ArrayList<Part>(partListName.values());
Comparator<? super Part> byName = Comparator.comparing(Part::getPartName);
Collections.sort(partListCurr, byName);
}
public void sortByNumber() {
partListCurr.clear();
partListCurr = new ArrayList<Part>(partListName.values());
Comparator<? super Part> byNumber = Comparator.comparing(Part::getPartNumber);
Collections.sort(partListCurr, byNumber);
}
public int size() {
return this.partListNumb.size();
}
public Part getPartByNumber(Long partNumber) {
return partListNumb.get(partNumber);
}
public Part getPartByName(String partName) {
return partListName.get(partName);
}
public static String[] getStrings() {
String[] strings = new String[partListCurr.size()];
for (int i = 0; i < partListCurr.size(); i++) {
Part part = partListCurr.get(i);
strings[i] = part.getPartName() + part.getPartNumber() + part.getQuantity();
}
return strings;
}
public static Part get(int i) {
if (partListCurr.size() == 0) {
partListCurr = new ArrayList<Part>(partListName.values());
}
return partListCurr.get(i);
}
}
Main.java
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import java.io.File;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class Main extends Application {
private static File selectedFile;
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("ui.fxml"));
primaryStage.setTitle("");
primaryStage.setScene(new Scene(root));
primaryStage.show();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we) {
DatabaseHandler.saveDatabase(PartList.getInstance());
}
});
}
public static void setSelectedFile(File file) {
selectedFile = file;
}
public static File getSelectedFile() {
return selectedFile;
}
public static void main(String[] args) {
launch(args);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.