Exemplo n.º 1
0
        public string ServeCustomer(StockController controller)
        {
            Thread.Sleep(Rnd.NextInt(5));
            TShirt shirt = TShirtProvider.SelectRandomShirt();
            string code  = shirt.Code;

            bool custSells = Rnd.TrueWithProb(1.0 / 6.0);

            if (custSells)
            {
                int quantity = Rnd.NextInt(9) + 1;
                controller.BuyShirts(code, quantity);
                return($"Bought {quantity} of {shirt}");
            }
            else
            {
                bool success = controller.TrySellShirt(code);
                if (success)
                {
                    return($"Sold {shirt}");
                }
                else
                {
                    return($"Couldn't sell {shirt}: Out of stock");
                }
            }
        }
Exemplo n.º 2
0
        public string ServeCustomer(StockController controller, LogTradesQueue bonusQueue)
        {
            Thread.Sleep(Rnd.NextInt(20));
            TShirt shirt = TShirtProvider.SelectRandomShirt();
            string code  = shirt.Code;

            bool custSells = Rnd.TrueWithProb(1.0 / 6.0);

            if (custSells)
            {
                int quantity = Rnd.NextInt(9) + 1;
                controller.BuyShirts(code, quantity);
                bonusQueue.QueueTradeForLogging(
                    new Trade(this, shirt, TradeType.Purchase, quantity));
                return($"Bought {quantity} of {shirt}");
            }
            else
            {
                bool success = controller.TrySellShirt(code);
                if (success)
                {
                    bonusQueue.QueueTradeForLogging(
                        new Trade(this, shirt, TradeType.Sale, 1));
                    return($"Sold {shirt}");
                }
                else
                {
                    return($"Couldn't sell {shirt}: Out of stock");
                }
            }
        }
Exemplo n.º 3
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);
            }
        }