Exemplo n.º 1
0
        public void Work(StockController stockController, TimeSpan workDay)
        {
            //Each sales person gets a random sequence
            Random   rand  = new Random(Name.GetHashCode());
            DateTime start = DateTime.Now;

            while (DateTime.Now - start < workDay)
            {
                Thread.Sleep(rand.Next(100));
                bool   buy      = rand.Next(6) == 0;
                string itemName = Program.AllShirtNames[rand.Next(Program.AllShirtNames.Count)];
                if (buy)
                {
                    int quantity = rand.Next(9) + 1;
                    stockController.BuyStock(itemName, quantity);
                    DisplayPurchase(itemName, quantity);
                }
                else
                {
                    bool success = stockController.TrySellItem(itemName);
                    DisplaySaleAttempt(success, itemName);
                }
            }

            Console.WriteLine("SalesPerson {0} signing off", this.Name);
        }
Exemplo n.º 2
0
        public void ServeCustomer(StockController controller)
        {
//			Thread.Sleep(Rnd.NextInt(100));
            string code = TShirtProvider.SelectRandomShirt().Code;

            bool buy = Rnd.TrueWithProb(0.1);

            if (buy)
            {
                int quantity = Rnd.NextInt(17) + 1;
                controller.BuyStock(code, quantity);
                DisplayPurchase(code, quantity);
            }
            else
            {
                bool success = controller.TrySellItem(code);
                DisplaySaleAttempt(success, code);
            }
        }