Write a JAVA program to monitor the flow of an item into an out of a warehouse. The warehouse has numerous deliveries and shipments for this item (a widget) during the time period covered. A shipment out (an order) is billed at a profit of 50% over the cost of the widget. Unfortunately each incoming shipment may have a different cost associated with it. The accountants of the firm have instituted a last-in, first out system for filling orders. This means that the newest widget are the first ones sent out to satisfy an order. This method of inventory can be represented by a stack. The Push procedure will insert an incoming shipment while a Pop should be called for a shipment out. Each data record in the text file warehouse.txt will consist of one shipment per line with fields (separated by white space of)
I or O (char) shipment coming IN or shipment going OUT
# (integer) quantity of the shipment
Cost (float) cost per widget of the shipment (Incoming only)
Vendor (String) name of the company sending or receiving the shipment
Write the necessary procedures to store the shipments received and to process the orders. The output for an order consists of the quantity and the total costs of the widget in the order. Each widget price is 50% higher than its cost. The widgets used to fill an order may come from multiple shipments with different costs. If there are not sufficient widgets in inventory, use all the remaining and bill accordingly.
When the simulation terminates display the total amount owed to each of the suppliers (incoming), the number of widgets on hand and the total profit.
InventoryManager.java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
public class InventoryManager {
//Stack to store the shipment widgets.
WarehouseStack shipment = new
WarehouseStack();
//Queue to store order widgets to be
completed.
WarehouseQueue order = new
WarehouseQueue();
//Shipment object to store information about
widgets
Widget widgetShipment;
//Order object to store information about
widgets
Widget widgetOrder;
//Value use to track the total amount of order
widgets in the warehouse
int totalOrderOfWidgets = 0;
//Value use to track the total amount of
shipments widgets in the warehouse
int totalShipmentOfWidgets = 0;
//Set a new in the file.
String eol =
System.getProperty("line.separator");
//File object to hold the input file to be
process.
File inputFile;
//Reader object to read from input file
BufferedReader inputFileBuffer;
//File object to hold the output file to be
process.
File outputFile;
//Writer object to write to output file
BufferedWriter outputFileBuffer;
//Tax multiplier for the orderd goods
final double TAX;
public InventoryManager(File inputFile, File
outputFile) throws IOException{
this.TAX = 1.50;
this.inputFile=inputFile;
this.outputFile=outputFile;
outputFileBuffer = new
BufferedWriter
(new
FileWriter(this.outputFile));
inputFileBuffer = new
BufferedReader(new FileReader(
this.inputFile));
}
protected void processFile() throws
FileNotFoundException,IOException{
String line;//line to
read inputs from
String trimLine;
int lineCounter=0;
/**
* Loop through the input
file until all lines in the file are read.
*/
while ((line =
inputFileBuffer.readLine()) != null){
lineCounter++;
//Sting to store the each attributes about a shipment or an
order
//"\\s+" takes care of whitespaces between each attributes
trimLine = line.trim();
//checks that the trimmed line is not blank before processing
that
//line
if(!trimLine.equals("")){
String datavalue[] = trimLine.split("\\s+");
//gets the first value from the
readline
char widgetType = datavalue[0].charAt(0);
int widgetAmount;
double widgetCost;
String widgetName;
//check wether an Order or Shipment
switch (widgetType) {
case 'l':{
try{ //try and catch invalid data from the file
//in this case the line where the error occurred
//will not be processed.
widgetAmount =
Integer.parseInt(datavalue[1]);
widgetCost =
Double.parseDouble(datavalue[2]);
widgetName = datavalue[3].trim();
if(widgetName.length()==0){
throw new NumberFormatException();
}
widgetShipment = new Widget(widgetType,widgetAmount,
widgetCost,widgetName);
processShipment();
break;
}
catch(NumberFormatException ex){ // handle your exception
System.out.println("Error in Line "+lineCounter
+" : "+line);
break;
}
}
case 'o':{
try{//try and catch invalid data from the file
//in this case the line where the error occurred
//will not be processed.
widgetAmount= Integer.parseInt(datavalue[1]);
widgetName = datavalue[2].trim();
if(widgetName.length()==0){
throw new NumberFormatException();
}
widgetOrder = new Widget(widgetType,widgetAmount,
widgetName);
processOrder();
break;
}
catch(NumberFormatException ex){ // handle your exception
System.out.println("Error in Line "+lineCounter
+" : "+line);
break;
}
}
default:{
System.out.println("Not an order or shipment at Line: "
+line);
}
}
}
}
//checks the queue for
any remaining orders that need processing
if(order.peek()!=null){
outputFileBuffer.write("Orders that are waiting to be
processed:\n");
//continuously check for remaining orders in the queue
while(order.peek()!=null){
widgetOrder=order.peek();
//write the remaining order to output file
outputFileBuffer.write(widgetOrder.toString()+eol);
//remove the fully process from the WarehouseQueue
order.dequeue();
}
}
//close output file
after processing is finish.
outputFileBuffer.close();
//closes input file
after processing is finish
inputFileBuffer.close();
}
private void processShipment() throws
IOException{
//A double to store the
cost of a order amount and cost of widget.
double cost;
//check if total amount
of widgets is zero
if(totalOrderOfWidgets==0){
//increase the total amount of shipment in the warehouse
totalShipmentOfWidgets +=widgetShipment.getAmountOfWidget();
//add the new shipment to the shipment stack
shipment.push(widgetShipment);
}
//check if the new
shipment widgets is greater than the total order widgets
else
if(totalOrderOfWidgets<widgetShipment.getAmountOfWidget()){
do{
//get the first Order Objetc in the WarehouseQueue
widgetOrder = order.peek();
//checks if the front of the queue is empty
if(widgetOrder==null){
throw new NoSuchElementException("Underflow Exception");
}
int newShipmentAmount = widgetShipment.getAmountOfWidget();
//calculate the cost order amount
cost = (widgetShipment.getCostOfWidget()*
widgetOrder.getRemainingWidgets())*TAX;
//set the order cost
widgetOrder.setCostOfWidget(cost);
widgetOrder.addShipment(widgetOrder.getRemainingWidgets(),
widgetShipment.getCostOfWidget(),widgetShipment.getVendor());
// decrement the total order amount but the remaining amount
//of order widgets
totalOrderOfWidgets
-=widgetOrder.getRemainingWidgets();
widgetShipment.setAmountOfWidget(newShipmentAmount
-widgetOrder.getRemainingWidgets());
//write order to output file
outputFileBuffer.write(widgetOrder.toString()+eol);
//remove the fully process from the WarehouseQueue
order.dequeue();
}
while(totalOrderOfWidgets>0);
if(widgetShipment.getAmountOfWidget()>0){
//shipments that still have widgets are push to the
//WarehouseStack
shipment.push(widgetShipment);
//increment the total shipment widgets by the remaining
// new shipment about
totalShipmentOfWidgets=widgetShipment.getAmountOfWidget();
}
}
//check if total amount
of order widgets are greater than/equal to
//new shipment
else
if(totalOrderOfWidgets>=widgetShipment.getAmountOfWidget()){
do{
widgetOrder = order.peek();
//checks if the front of the queue is empty
if(widgetOrder==null){
throw new NoSuchElementException("Underflow Exception");
}
int orderAmount= widgetOrder.getRemainingWidgets();
int shipmentAmount= widgetShipment.getAmountOfWidget();
if(orderAmount<=shipmentAmount){
//calculate the cost order amount
cost = (widgetShipment.getCostOfWidget()*
widgetOrder.getRemainingWidgets())*TAX;
//set the cost of the order
widgetOrder.setCostOfWidget(cost);
//decrement total amount of order
widgetOrder.addShipment(widgetOrder.getRemainingWidgets(),
widgetShipment.getCostOfWidget(),widgetShipment.getVendor());
totalOrderOfWidgets -=widgetOrder.getRemainingWidgets();
//set new shipment amount new shipment
widgetShipment.setAmountOfWidget(widgetShipment.getAmountOfWidget()
-orderAmount);
//decrement the remaining order amount for the order
widgetOrder.setRemainingWidgets(orderAmount);
outputFileBuffer.write(widgetOrder.toString()+eol);
//remove first object from queue
order.dequeue();
}
//check if the first object in the queue remain amount is
less
//than the new shipment widget amount
else if(orderAmount>shipmentAmount){
//calculate the cost of the order amount and set the order
//cost
cost = (widgetShipment.getCostOfWidget()*
shipmentAmount)*TAX;
widgetOrder.setCostOfWidget(cost);
widgetOrder.addShipment(shipmentAmount,widgetShipment.getCostOfWidget(),
widgetShipment.getVendor());
totalOrderOfWidgets
-=shipmentAmount;
widgetShipment.setAmountOfWidget(widgetShipment.getAmountOfWidget()
-widgetOrder.getRemainingWidgets());
widgetOrder.setRemainingWidgets(shipmentAmount);
}
}
while(widgetShipment.getAmountOfWidget()>0);
if(widgetShipment.getAmountOfWidget()>0){
//push the element to the stack and increment the total
amount
//of shipment widgets
shipment.push(widgetShipment);
totalShipmentOfWidgets=widgetShipment.getAmountOfWidget();
}
}
}
private void processOrder() throws
IOException{
double cost;
//insert and increment
the total order of widgets if
//shipment total is
zero
if(totalShipmentOfWidgets==0){
order.enqueue(widgetOrder);
totalOrderOfWidgets
+=widgetOrder.getRemainingWidgets();
}
//check if the shipment
total is less than remaining widgets order
else
if(totalShipmentOfWidgets<widgetOrder.getRemainingWidgets()){
//continuously process an order until the shipment total is
zero
//several shipment may be on the stack that can process an
order
do{
widgetShipment = shipment.peek();
//checks if the top of the stack is empty
if(widgetShipment==null){
throw new NoSuchElementException("Underflow Exception");
}
cost = (widgetShipment.getAmountOfWidget()*
widgetShipment.getCostOfWidget())*TAX;
widgetOrder.setCostOfWidget(cost);
widgetOrder.addShipment(widgetShipment.getAmountOfWidget(),
widgetShipment.getCostOfWidget(),widgetShipment.getVendor());
totalShipmentOfWidgets -= widgetShipment.getAmountOfWidget();
totalOrderOfWidgets = widgetOrder.getRemainingWidgets()-
widgetShipment.getAmountOfWidget();
widgetOrder.setRemainingWidgets(widgetShipment.getAmountOfWidget());
shipment.pop();
}
while(totalShipmentOfWidgets>0);
//the processed order is then added to the queue
order.enqueue(widgetOrder);
}
//check if the shipment
total is greater than/equal to the new order
//widget
else
if(totalShipmentOfWidgets>=widgetOrder.getRemainingWidgets()){
//amount of widgets order remaining to be processed.
int remainingAmount =widgetOrder.getRemainingWidgets();
//continuously process an order if the remaining widgets in
an
//order is not zero
do{
widgetShipment = shipment.peek();
//checks if the top of the stack is empty
if(widgetShipment==null){
throw new NoSuchElementException("Underflow Exception");
}
int shipmentAmount =
widgetShipment.getAmountOfWidget();
if(shipmentAmount<=remainingAmount){
cost=(shipmentAmount*widgetShipment.getCostOfWidget())*TAX;
widgetOrder.setCostOfWidget(cost);
widgetOrder.addShipment(shipmentAmount,widgetShipment.getCostOfWidget(),
widgetShipment.getVendor());
remainingAmount-=shipmentAmount;
totalShipmentOfWidgets
-=shipmentAmount;
shipment.pop();
}
else
if(shipmentAmount>remainingAmount){
cost =(remainingAmount*widgetShipment.getCostOfWidget())*TAX;
widgetOrder.setCostOfWidget(cost);
widgetOrder.addShipment(remainingAmount,widgetShipment.getCostOfWidget(),
widgetShipment.getVendor());
totalShipmentOfWidgets-=remainingAmount;
widgetShipment.setAmountOfWidget(shipmentAmount-remainingAmount);
remainingAmount = 0;
}
}while(remainingAmount>0);
//write the fully processed order to the output
file
outputFileBuffer.write(widgetOrder.toString()+eol);
}
}
}
ShipmentsToOrder.java
public class ShipmentsToOrder {
//The amount of widgets used for the
order.
private int amount;
//The amountWidgetsUsed times the cost of the
widget
//for the order
private double cost;
//The vendor that was used to fill the
order
private String vendor;
/**
* Shipment to Order Constructor.
* @param amount
* @param cost
* @param vendor
*/
public ShipmentsToOrder(int amount, double cost,
String vendor){
this.amount=amount;
this.cost=cost;
this.vendor=vendor;
}
/**
*
* @return The a string representation of
the ShipmentsToOrder object.
*/
@Override
public String toString(){
return
"\t"+this.amount+"\t\t"+this.cost+"\t"+this.vendor+"\n";
}
}
WarehouseManager.java
import java.io.File;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class WarehouseManager {
public static void main(String[] args) throws
IOException {
Scanner in = new
Scanner(System.in);
int
inputtextFileUse=0;
boolean
input=true;
File inputFile=new
File("BlankFile");
File outputFile = new
File("BlankFile");
//Continuously display
to the user the input file to choose from.
while(input){
try{
System.out.print("File warehouse.txt=1.\n"
+ "File hw2in.txt=2.\n"
+ "Enter 1 or 2 for the input file to read from:");
//Scan in the
inputtextFileUse = in.nextInt();
if(!(inputtextFileUse<1 ||inputtextFileUse>2)){
input=false;
break;
}
System.out.println("Please follow directions! "
+ "Enter a single digit(1-2)!");
}
// Catch the user invalid input
catch (InputMismatchException ime) {
//skips over the invalid characters that are sitting input
//stream
input=true;
in.skip(".*");
System.out.println("Please follow directions! "
+ "Enter a single digit(1-2)!");
}
}
switch(inputtextFileUse){
case 1:{
inputFile = new File("warehouse.txt");
outputFile = new File("hw1out.txt");
break;
}
case 2:{
inputFile = new File("hw2in.txt");
outputFile = new File("hw2out.txt");
break;
}
}
//create an Inventory
object with the input and output file and then
//process the widgets in
the input file.
if(inputFile.exists()){
InventoryManager
inventoryManager = new
InventoryManager(inputFile,outputFile);
inventoryManager.processFile();
}
else
if(!inputFile.exists()){
System.out.println("No file exists with that name.\n\nPlease
enter"
+ " a valid file name.Program terminated.");
}
}
}
WarehouseQueue.java
import java.util.NoSuchElementException;
class WarehouseQueue{
protected LinkedList frontOfQueue,
rearOfQueue;
//public int size;
/**
* Queue Constructor that initialize the
front an d back of the queue to be
* null.
*/
public WarehouseQueue(){
frontOfQueue =
null;
rearOfQueue =
null;
}
/**
* Function to insert an element to
the back OfQueue of the queue.
* @param widget widget object to be
added to the queue.
*/
public void enqueue(Widget widget){
LinkedList nodeLink =
new LinkedList(widget, null);
if (rearOfQueue ==
null)
{
frontOfQueue = nodeLink;
rearOfQueue = nodeLink;
}
else
{
rearOfQueue.setLink(nodeLink);
rearOfQueue = rearOfQueue.getLink();
}
}
/**
* Method to remove frontOfQueue element
from the front of the queue.
* @return The widget object.
*/
public Widget dequeue(){
if (frontOfQueue ==
null)
throw
new NoSuchElementException("Underflow Exception");
LinkedList link =
frontOfQueue;
frontOfQueue =
link.getLink();
if (frontOfQueue ==
null)
rearOfQueue =
null;
return
link.getWidget();
}
/**
* Method to get the frontOfQueue element
from the front of the queue.
* @return
*/
public Widget peek(){
if (frontOfQueue ==
null){
return
null;
}
return
frontOfQueue.getWidget();
}
}
WarehouseStack.java
import java.util.NoSuchElementException;
class WarehouseStack{
protected LinkedList topOfStack
;
/**
* Stack Constructor that initialize the top of
the stack to be
* null.
*/
public WarehouseStack(){
topOfStack =
null;
}
/**
* Method to push an element to the
stack
* @param widget to be push onto the
topOfStack of the stack.
*/
public void push(Widget widget){
LinkedList nodeLink =
new LinkedList (widget, null);
if (topOfStack ==
null)
topOfStack = nodeLink;
else
{
nodeLink.setLink(topOfStack);
topOfStack = nodeLink;
}
}
/**
* Method to pop an element from the
stack.
* @return widget object
*/
public Widget pop(){
if (topOfStack ==
null){
throw new NoSuchElementException("Underflow Exception") ;
}
LinkedList link =
topOfStack;
topOfStack =
link.getLink();
return
link.getWidget();
}
/**
* Method to check the topOfStack element
of the stack
* @return widget object
*/
public Widget peek(){
if (topOfStack ==
null)
return null;//throw new NoSuchElementException("Underflow
Exception") ;
return
topOfStack.getWidget();
}
}
Widget.java
import java.text.DecimalFormat;
import java.util.ArrayList;
public class Widget {
private char widgetType;
//stores the amount of widget for the shipment
or order
private int amountOfWidget;
//stores the cost of a widget for the shipment
or order
private double costOfWidget;
//stores the vendor of the shipment or
order
private String vendor;
//stores the amount of widgets are remaining for
an order
private int widgetsLeftForProcess;
private ArrayList<ShipmentsToOrder>
shipmentsToOrder;
DecimalFormat df = new
DecimalFormat("0.00##");
public Widget(char widgetType, int
amountOfWidget, double
costOfWidget, String vendor){
this.widgetType=widgetType;
this.amountOfWidget=amountOfWidget;
this.costOfWidget=costOfWidget;
this.vendor=vendor;
}
public Widget(char widgetType, int
amountOfWidget,
String vendor){
this.widgetType=widgetType;
this.amountOfWidget=amountOfWidget;
this.widgetsLeftForProcess=amountOfWidget;
this.costOfWidget=0.0;
this.vendor=vendor;
this.shipmentsToOrder=new ArrayList<>();
}
public char getWidgetType(){
return widgetType;
}
public int getAmountOfWidget(){
return
amountOfWidget;
}
/**
*
* @param amount
*/
public void setAmountOfWidget(int amount){
amountOfWidget =
amount;
}
/**
*
* @return The amount of widgets left to be
process for a specific order.
*/
public int getRemainingWidgets(){
return
widgetsLeftForProcess;
}
/**
* Reduce the amount of widgets to the
amount left to be processed.
* @param amount The amount to reduce a
specific order amount by.
*/
public void setRemainingWidgets(int
amount){
widgetsLeftForProcess -=
amount;
}
/**
*
* @return The cost of the shipment or
order.
*/
public double getCostOfWidget (){
return
costOfWidget;
}
/**
* Set the Cost of an widgets order.
* @param cost The cost of the shipment
cost per amount of widgets for the
* order.
*/
public void setCostOfWidget(double cost){
costOfWidget+=cost;
}
/**
*
* @return The vendor name of the shipment
or order.
*/
public String getVendor(){
return vendor;
}
protected String printShipments(){
String x="";
x =
shipmentsToOrder.stream().map((shipmentsToOrder1) ->
shipmentsToOrder1.toString()).reduce(x, String::concat);
return x;
}
protected void addShipment(int
amountWidgetsUsed, double CostOfShipment,
String orderVendor){
shipmentsToOrder.add(new
ShipmentsToOrder(amountWidgetsUsed,CostOfShipment,
orderVendor));
}
/**
*
* @return The string representation of an
order and the shipments that are
* related to the order.
*/
@Override
public String toString(){
return
this.getVendor()+"\t\t"+
this.getAmountOfWidget()+"\t\t"+
df.format(this.getCostOfWidget())+"\n"+
this.printShipments();
}
}
LinkedList.java
class LinkedList{
protected Widget widget;
protected LinkedList link;
public LinkedList(Widget widget,LinkedList
nextNode){
this.widget =
widget;
link = nextNode;
}
/**
* Method to set link to next Node
* @param nextNode
*/
public void setLink(LinkedList nextNode){
link = nextNode;
}
/**
* Method to set widget to current
Node
* @param widget
*/
public void setData(Widget widget){
this.widget =
widget;
}
/**
* Method to get link to next node
* @return
*/
public LinkedList getLink(){
return link;
}
/**
* Method to get widget from current
Node
* @return a widget object from the
LinkedList
*/
public Widget getWidget(){
return
this.widget;
}
}
warehouse.txt
s 100 10.50 RCA
s 50 10.25 RF Micro
o 75 Boeing
o 50 Hewlet Packard
s 60 11.00 RCA
o 25 Intel

Write a JAVA program to monitor the flow of an item into an out of a...
language C++ Write a program to handle the flow of widgets into and out of a warehouse. The warehouse will have numerous deliveries of new widgets and orders for widgets. The widgets in a filled order are billed at a profit of 50 percent over their cost. Each delivery of new widgets may have a different cost associated with it. The accountants for the firm have instituted a last-in, first-out system for filling orders. This means that the newest widgets...
Written in Java I have an error in the accountFormCheck block can i get help to fix it please. Java code is below. I keep getting an exception error when debugging it as well Collector.java package userCreation; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.event.ActionEvent; import javafx.fxml.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.text.Text; import javafx.stage.*; public class Controller implements Initializable{ @FXML private PasswordField Password_text; @FXML private PasswordField Confirm_text; @FXML private TextField FirstName_text; @FXML private TextField LastName_text;...
The Computer Warehouse purchases its inventory from more than a dozen different vendors. Orders are placed via telephone, fax, or on the supplier’s Web site. Most orders are delivered the next day. Most orders are filled completely in one shipment, but sometimes a supplier is out of stock of a particular item. In such situations, the bulk of the order is shipped immediately and the out-of-stock item is shipped separately as soon as it arrives (such shipments of back orders...
M. Lowenthal You are to use Linked Lists to do this program The "XYZ Widget Store receivee shipments of widgots at varlous oosts. The store's polcy isto charge a 30% markup, and to sol widgets which were received earlier before widgets whic were received lator. This is called a First In First Out policy (FIFO) a program using lnked lists that reeds in 3 types of input data and does the following widgets sold he receipt of a quantity of...
Use case diagram for Mail Order System Requirements(draw by use case diagram) This software system is developed to support mail order business operations. In particular software shall: - Keep track of sales (including orders, payments, and shipments). For each order a record shall be kept identifying the customer, the ZIP code, the salesperson, item ordered, the quantity, and amount due. - Record shall be kept for each customer who made a purchase in the past year. Such record shall include...
O’Brien Corporation is a midsize, privately owned, industrial instrument manufacturer supplying precision equipment to manufacturers in the Midwest. The corporation is 10 years old and uses an integrated ERP system. The administrative offices are located in a downtown building and the production, shipping, and receiving departments are housed in a renovated warehouse a few blocks away. What are the threats that may face production operations and what could be the possible controls for those threats? [3 points] Customers place orders...
Monrose Park had the following transactions during the month of November 2018. Nov 2 Purchased 1,000 widgets for $20 per unit on credit Nov 5 Sold 900 widgets for $55 each for cash Nov 10 Purchased 500 widgets for $25 per unit on credit Nov 18 Sold 100 widgets for $60 each on credit Nov 29 Sold 300 widgets for $50 each for cash Monrose Park uses a perpetual inventory system and the FIFO inventory valuation method. There were no widgets in the company’s opening...
Identify the cost being described according to the five basic costs of inventory. Write the letter of the correct answer. A. Carrying or Holding Cost B. Safety stock cost C. Item cost D. Stock out cost E. Ordering or setup cost 1. Cost of moving the goods to temporary storage 2. Amount of damaged, broken, pilfered and deteriorated items 3. Initial cost of the items 4. Potential depreciation of the material over time 5. Acquiring or renting a new warehouse...