package PS7; import javax.swing.*; public class FactoryTest { public static void main(String[] args) { ArrayQueue[] prodLine= new ArrayQueue[2]; for (int i=0; i < 2; i++) prodLine[i]= new ArrayQueue(); Robot1 r= new Robot1(); TransferCar t= new TransferCar(); StackArea[] s= new StackArea[6]; for (int i= 0; i < s.length; i++) s[i]= new StackArea(); int[] product= new int[2]; for (int time=0; time < 5; time++) { for (int j=0; j < 2; j++) { // Loop over the 2 production lines String text= JOptionPane.showInputDialog("Enter product (0-5) made on line " + j); product[j]= Integer.parseInt(text); for (int k=0; k < (8- 4*j); k++) // 8 items/batch in line 0, 4 items/batch in line 1 prodLine[j].add(new Product(product[j])); } // Robot picks from line 0,1,0; places product in its storage area, qty 4 r.moveProduct(prodLine[0], s[product[0]], 4); r.moveProduct(prodLine[1], s[product[1]], 4); r.moveProduct(prodLine[0], s[product[0]], 4); // Prompt for order quantities to ship int[] orderQty= new int[6]; for (int i=0; i < orderQty.length; i++) { String text= JOptionPane.showInputDialog("Enter qty of product " + i + " to ship:"); orderQty[i]= Integer.parseInt(text); } // Transfer car picks and places at stretch wrapper for shipment // Also outputs serial numbers of all products in shipment, and backorder quantities t.pickProduct(s, orderQty); } System.exit(0); } } class Product { private int prodType; private int serialNbr; private static int lastSerialNbr; public Product(int pt) { prodType= pt; serialNbr= lastSerialNbr++; } public int getProdType() { return prodType; } public int getSerialNbr() { return serialNbr; } } class Robot1 { public void moveProduct(ArrayQueue line, StackArea s, int qty) { // Need logic if not enough to serve qty. Can't use exceptions yet. for (int i=0; i< qty; i++) { Product p= (Product) line.remove(); s.addToStack(p); } } } class TransferCar { private static int orderNbr= 0; public void pickProduct(StackArea[] s, int[] order) { System.out.println("Products shipped for order: " + orderNbr++); for (int i=0; i < 6; i++) for (int j=0; j < order[i]; j++) { Product p= (Product) s[i].getFromStack(); System.out.println("Product " + p.getProdType() + " , serial number " + p.getSerialNbr()); } } } class StackArea { private ArrayStack[] s; private int nextArrayStack; private int numObj; public StackArea() { s= new ArrayStack[4]; for (int i=0; i < 4; i++) s[i]= new ArrayStack(); } public void addToStack(Product p) { s[nextArrayStack].push(p); nextArrayStack = (nextArrayStack+1)%4; numObj++; } public Product getFromStack() { if (nextArrayStack==0) nextArrayStack = 3; else nextArrayStack = nextArrayStack-1; numObj--; return (Product) s[nextArrayStack].pop(); } public int getTotalSize() { return numObj; } }