public void Run(long capacity, string command) { Bag bag = new Bag(capacity); CommandParser commandParser = new CommandParser(command); List <Hoard> items = commandParser.ParseCommand(); foreach (var item in items) { if (item.Name.ToLower() == "gold") { bag.AddGoldItem(item); } else if (item.Name.Substring(item.Name.Length - 3).ToLower() == "gem") { bag.AddGemItem(item); } else if (item.Name.Length == 3) { bag.AddCashItem(item); } } Console.WriteLine(bag); }
private static void InsertItem(string key, long value, Bag bag) { if (key.Length == 3) { CashItem cash = new CashItem(key, value); bag.AddCashItem(cash); } else if (key.Length >= 4 && key.ToLower().EndsWith("gem")) { GemItem gem = new GemItem(key, value); bag.AddGemItem(gem); } else if (key.ToLower().Equals("gold")) { GoldItem gold = new GoldItem(key, value); bag.AddGoldItem(gold); } }