Ejemplo n.º 1
0
        public void CollectItems(Bag bag, string[] safeContent)
        {
            Parser parser = new Parser();

            for (int i = 0; i < safeContent.Length; i += 2)
            {
                string inputName = safeContent[i];
                long   quantity  = long.Parse(safeContent[i + 1]);

                string name = parser.ParseItem(inputName);


                if (bag.Capacity >= (bag.TotalAmount + quantity))
                {
                    switch (name)
                    {
                    case "gem":

                        if (bag.TotalGemsAmount + quantity <= bag.Gold.Amount)
                        {
                            bag.AddGem(name, quantity);
                            bag.AddItem(name, quantity);
                        }
                        break;

                    case "cash":

                        if (bag.TotalCashAmount + quantity <= bag.TotalGemsAmount)
                        {
                            bag.AddCash(name, quantity);
                            bag.AddItem(name, quantity);
                        }
                        break;

                    case "gold":

                        bag.Gold.AddAmount(quantity);
                        bag.AddItem(name, quantity);
                        break;
                    }
                }

                else
                {
                    continue;
                }
            }
        }
Ejemplo n.º 2
0
        static void Main()
        {
            long capacity = long.Parse(Console.ReadLine());

            string[] safe = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Bag      bag  = new Bag(capacity);

            for (int i = 0; i < safe.Length; i += 2)
            {
                string itemName = safe[i];
                long   amount   = long.Parse(safe[i + 1]);
                bag.AddItem(itemName, amount);
            }

            Console.WriteLine(bag.ToString());
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            long capacity = long.Parse(Console.ReadLine());

            string[] safe = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

            var bag = new Bag(capacity);

            for (int i = 0; i < safe.Length; i += 2)
            {
                string name   = safe[i];
                long   amount = long.Parse(safe[i + 1]);

                var item = new Item(name, amount);

                if (item.Type == "Gold" || item.Type == "Gem" || item.Type == "Cash")
                {
                    bag.AddItem(item);
                }
            }

            Console.WriteLine(bag);
        }