public static void processOrder(Order order) { // Calculate order price Int32 subtotal, total, tax, shipping; subtotal = order.getUnitPrice() * order.getAmount(); tax = (Int32)(subtotal * TAXRATE); shipping = order.getAmount() * SHIPPINGRATE; total = subtotal + tax + shipping; }
// method to be run as the 'retailer thread' public void retailerFunc() { while (Program.ChickenFarmIsAlive()) { //sleep on startup of the loop (whenever the retailer finishes ordering) Thread.Sleep(100); if (priceWasCutArray[getId()]) { Random randNum = new Random(); // set the number of chickens to order Int32 numOfChickensToOrder = 980 / (nPrice); Order newOrder = new Order(); newOrder.setUnitPrice(nPrice); newOrder.setAmount(numOfChickensToOrder); //Sets the order credit card number between 1000 and 9999 newOrder.setCardNum(randNum.Next(1000, 9999)); newOrder.setThreadId(this.myId); //encode the order as a string String encodedOrder = Encoder.encode(newOrder); // keep sleeping until the buffer has an open cell while (Program.orderBuffer.IsFull()) { Thread.Sleep(randNum.Next(10, 100)); } // lock the buffer so the thread can input its encoded order lock (Program.orderBuffer) { Program.orderBuffer.setCell(encodedOrder); } // indicate that the ordering has been submitted and that the thread // shouldn't order again until the price is cut again priceWasCutArray[getId()] = false; } } }
public void setOrder(Order pOrder) { this.pOrder = pOrder; }
public static string encode(Order order) { return (order.ToString()); }