コード例 #1
0
ファイル: Employee.cs プロジェクト: Cenxus/SoftwareExam
        public void AddWare(string clothingType, double price, char size)
        {
            lock (_lock)
            {
                clothingFactory    factory   = null;
                InventorySingleton inventory = InventorySingleton.GetInventorySingleton();

                switch (clothingType.ToLower())
                {
                case "pants":
                    factory = new pantsFactory(price, size);
                    inventory.AddToInventory(factory.GetClothes());
                    Console.WriteLine(name + " added new " + clothingType + " " + inventory.ClothesList(clothingType).Count + " for sale.");
                    break;

                case "sweater":
                    factory = new sweaterFactory(price, size);
                    inventory.AddToInventory(factory.GetClothes());
                    Console.WriteLine(name + " added new " + clothingType + " " + inventory.ClothesList(clothingType).Count + " for sale.");
                    break;

                case "socks":
                    factory = new socksFactory(price, size);
                    inventory.AddToInventory(factory.GetClothes());
                    Console.WriteLine(name + " added new " + clothingType + " " + inventory.ClothesList(clothingType).Count + " for sale.");
                    break;

                default:
                    Console.WriteLine("Nothing found");
                    break;
                }
            }
        }
コード例 #2
0
        public void Browse()
        {
            InventorySingleton inventory = InventorySingleton.GetInventorySingleton();
            bool   bought = false;
            Random random = new Random();
            var    list   = new List <string> {
                "pants", "sweater", "socks"
            };
            int index = random.Next(list.Count);

            while (bought != true)
            {
                List <clothes> wares = inventory.ClothesList(list[index]);
                for (int i = 0; i < wares.Count; i++)
                {
                    int randomNumber = random.Next(0, 12);
                    if (randomNumber == 10)
                    {
                        Console.WriteLine(name + " bought a size " + wares[i].size + " " + wares[i].clothingType + " for " + wares[i].price + ".");
                        inventory.RemoveFromInventory(list[index], i);
                        bought = true;
                    }
                    else if (i == wares.Count)
                    {
                        i = 0;
                    }
                }
            }
        }
コード例 #3
0
        public void Buy(string clothingType)
        {
            InventorySingleton inventory = InventorySingleton.GetInventorySingleton();
            List <clothes>     wares     = inventory.ClothesList(clothingType);

            for (int i = 0; i < wares.Count; i++)
            {
                if (wares[i].price < _money)
                {
                    _money = money - wares[i].price;
                    Console.WriteLine(name + " bought " + wares[i].clothingType.ToLower() + " " + inventory.ClothesList(clothingType).Count + " from the store.");
                    inventory.RemoveFromInventory(clothingType, i);
                }
            }
        }