Beispiel #1
0
        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;
                }
            }
        }
Beispiel #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;
                    }
                }
            }
        }
Beispiel #3
0
        static void Main()
        {
            Employee           _store     = new Employee("Per", 01);
            Customer           _customer1 = new Customer("Pål", 02, 500);
            InventorySingleton inventory  = InventorySingleton.GetInventorySingleton();

            _store.AddWare("pants", 99.99, 'm');
            _store.AddWare("sweater", 199.99, 'l');
            _store.AddWare("socks", 99.99, 's');
            _customer1.Browse();
        }
Beispiel #4
0
        static void Main()
        {
            Employee        _store     = new Employee("Store", 01);
            List <Customer> _customers = new List <Customer>()
            {
                new Customer("Pål", 02), new Customer("Per", 03), new Customer("Espen", 03),
            };
            InventorySingleton inventory = InventorySingleton.GetInventorySingleton();

            _store.Start();
            foreach (var customer in _customers)
            {
                customer.Start();
            }

            Thread.Sleep(3000);

            foreach (var customer in _customers)
            {
                customer.Stop();
            }
            _store.Stop();

            Console.WriteLine("\n\nPress any key to exit.");
            Console.ReadKey();

            /*
             * clothingFactory factory = null;
             * Console.Write("Enter your clothing type: ");
             * string choice = Console.ReadLine();
             *
             * switch(choice.ToLower())
             * {
             *  case "pants":
             *      factory = new pantsFactory(20, 'M');
             *      break;
             *  case "weater":
             *      factory = new sweaterFactory(40, 'L');
             *      break;
             *  case "socks":
             *      factory = new socksFactory(16, 'S');
             *      break;
             *  default:
             *      Console.WriteLine("Nothing found");
             *      break;
             * }
             *
             * clothes clothes = factory.GetClothes();
             * Console.WriteLine("\n The details of your choice are written bellow: \n");
             * Console.WriteLine("Clothing type: {0}\nPrice: {1}\nSize: {2}",
             *  clothes.clothingType, clothes.price, clothes.size);
             * Console.ReadKey();*/
        }
Beispiel #5
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);
                }
            }
        }