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
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
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
Bs van into sales associate As 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 As
delivery van warehouse and salesperson Bs 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.
public class BikePart { private String name; private int number; private double price; private double salesPrice; private boolean onSale; public BikePart(String name, int number, double price, double salesPrice, boolean onSale) { this.name = name; this.number = number; this.price = price; this.salesPrice = salesPrice; this.onSale = onSale; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public double getSalesPrice() { return salesPrice; } public void setSalesPrice(double salesPrice) { this.salesPrice = salesPrice; } public boolean isOnSale() { return onSale; } public void setOnSale(boolean onSale) { this.onSale = onSale; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BikePart bikePart = (BikePart) o; if (number != bikePart.number) return false; return name != null ? name.equals(bikePart.name) : bikePart.name == null; } @Override public String toString() { return "BikePart{" + "name='" + name + '\'' + ", number=" + number + ", price=" + price + ", salesPrice=" + salesPrice + ", onSale=" + onSale + '}'; } }
// Inventory class
import java.util.Comparator; public class Inventory { private BikePart bp; private int count; /** * Old style - uses anonymous inner class */ public static ComparatorSORT_BY_NAME = new Comparator () { @Override public int compare(final Inventory o1, final Inventory o2) { String o1Name = o1.getBp().getName() + o1.getBp().getName(); String o2Name = o2.getBp().getName() + o2.getBp().getName(); return o1Name.compareTo(o2Name); } }; /** * New style - uses lambda expression */ public static Comparator SORT_BY_NUMBER = (Inventory i1, Inventory i2) -> (Integer.compare(i1.getBp().getNumber(), i2.getBp().getNumber())); public Inventory(BikePart bp, int count) { this.bp = bp; this.count = count; } public BikePart getBp() { return bp; } public void setBp(BikePart bp) { this.bp = bp; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } @Override public String toString() { return "Inventory{" + "bp=" + bp + ", count=" + count + '}'; } }
//warehouse class
import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class WareHouse { private ListwhDB; public WareHouse() { whDB = new ArrayList (); } private Inventory findInventory(BikePart bp) { for (Inventory i : whDB) { if (i.getBp().equals(bp)) return i; } return null; } private void updateInventory(Inventory i, BikePart b, int qty) { i.getBp().setPrice(b.getPrice()); i.getBp().setSalesPrice(b.getSalesPrice()); i.getBp().setOnSale(b.isOnSale()); i.setCount(i.getCount() + qty); } public void addInventory(BikePart bp, int qty) { Inventory i = findInventory(bp); if (i != null) updateInventory(i, bp, qty); else whDB.add(new Inventory(bp,qty)); } public void updateWareHouseDB(String fileName) throws FileNotFoundException{ File file = new File(fileName); Scanner read = new Scanner(file); while (read.hasNextLine()) { String line = read.nextLine(); String regExp = "\\s*(\\s|,)\\s*"; String[] bpi = line.split(regExp); BikePart bp = new BikePart(bpi[0], Integer.parseInt(bpi[1]), Double.parseDouble(bpi[2]), Double.parseDouble(bpi[3]), bpi[4].equals("true") ? true : false); int qty = Integer.parseInt(bpi[5]); addInventory(bp, qty); } } public Inventory sellPart(int partNum) { Inventory f = null; for (Inventory i : whDB) { if (i.getBp().getNumber() == partNum) { f = i; break; } } if (f != null) updateInventory(f,f.getBp(),-1); return f; } public Inventory findPartByName(String partName) { for (Inventory i : whDB) { if (i.getBp().getName().equals(partName)) return i; } return null; } public List getInventory() { return whDB; } public void saveWarehouseDB(String fileName) { try{ PrintWriter writer = new PrintWriter(fileName, "UTF-8"); for (Inventory i : whDB) writer.println(i.getBp().getName() + "," + i.getBp().getNumber() + "," + i.getBp().getPrice() + "," + i.getBp().getSalesPrice() + "," + i.getBp().isOnSale() + "," + i.getCount()); writer.close(); } catch (IOException e) { System.out.println("file error!"); e.printStackTrace(); } } }
//ProcessCommand class
import java.io.FileNotFoundException; import java.util.Collections; import java.util.Date; import java.util.Scanner; public class ProcessCommands { private Scanner in; private WareHouse wh; public ProcessCommands(WareHouse wh) { this.wh = wh; in = new Scanner(System.in); } public void processCommands() { String command = ""; while (!command.equalsIgnoreCase("quit")) { System.out.print("Enter command (read, enter, sell, display, sortname, sortnumber, quit): "); command = in.nextLine(); switch (command.toLowerCase()) { case "read": doRead(); break; case "enter": doEnter(); break; case "sell": doSell(); break; case "display": doDisplay(); break; case "sortname": doSortName(); break; case "sortnumber": doSortNumber(); break; default: if (!command.equals("quit")) System.out.println("Invalid command."); break; } } } private void doRead() { System.out.print("Enter filename: "); String fileName = in.nextLine(); try { wh.updateWareHouseDB(fileName); } catch (FileNotFoundException e) { System.out.println("Invalid file name."); } } private void doEnter() { System.out.print("Enter partname: "); String partName = in.nextLine(); System.out.print("Enter partnum: "); int partNum = Integer.parseInt(in.nextLine()); System.out.print("Enter price: "); double price = Double.parseDouble(in.nextLine()); System.out.print("Enter sales price: "); double salsePrice = Double.parseDouble(in.nextLine()); System.out.print("Enter onsale (true or false): "); boolean onsale = Boolean.parseBoolean(in.nextLine()); System.out.print("Enter warehouse quantity: "); int quantity = Integer.parseInt(in.nextLine()); wh.addInventory(new BikePart(partName,partNum,price,salsePrice,onsale),quantity); } private void doSell() { System.out.print("Enter part number: "); int partNum = Integer.parseInt(in.nextLine()); Inventory i = wh.sellPart(partNum); if (i == null) System.out.println("Part not in DB."); else System.out.println(i + (new Date()).toString()); } private void doDisplay() { System.out.print("Enter part name: "); String partName = in.nextLine(); Inventory i = wh.findPartByName(partName); if (i != null) System.out.println(i); else System.out.println("Part not found."); } private void doSortName() { Collections.sort(wh.getInventory(), Inventory.SORT_BY_NAME); for (Inventory i : wh.getInventory()) { System.out.println(i); } } private void doSortNumber() { Collections.sort(wh.getInventory(), Inventory.SORT_BY_NUMBER); for (Inventory i : wh.getInventory()) { System.out.println(i); } } }
//Main class
import java.io.FileNotFoundException; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; public class Main { //private static WareHouse wh = new WareHouse(); private final static String WH_DB_FILENAME = "warehouseDB.txt"; public static void main(String[] args) { WareHouse wh = new WareHouse(); try { wh.updateWareHouseDB(WH_DB_FILENAME); } catch (FileNotFoundException e) { System.out.println("Missing warehouseDB.txt"); e.printStackTrace(); } ProcessCommands pc = new ProcessCommands(wh); pc.processCommands(); wh.saveWarehouseDB(WH_DB_FILENAME); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started