Ejemplo n.º 1
0
        private static ShoppingBasket createShoppingBasket(string[] items)
        {
            ShoppingBasket shoppingBasket = new ShoppingBasket();

            foreach (string item in items)
            {
                if (!string.IsNullOrWhiteSpace(item))
                {
                    string caseInsentiveItem = item.ToLower();
                    if (nameToGroceryItemDataMap.ContainsKey(caseInsentiveItem))
                    {
                        GroceryItemData groceryItem = nameToGroceryItemDataMap [caseInsentiveItem];
                        if (groceryItem != null)
                        {
                            shoppingBasket.addItem(groceryItem);
                        }
                    }
                    else
                    {
                        Console.WriteLine("error - no data for {0}", caseInsentiveItem);
                    }
                }
            }
            return(shoppingBasket);
        }
Ejemplo n.º 2
0
 private static void displayPromoInfoToConsole(GroceryItemData item, IPromotion promoInfo)
 {
     if (promoInfo.getQuantityToGetPromoPrice() == 1)
     {
         Console.WriteLine(item.Name + " \t" + MoneyDisplayUtil.formatMoneyDisplay(promoInfo.getTotalPriceForQuantityMet()));
     }
     else
     {
         Console.WriteLine(item.Name + " (X" + promoInfo.getQuantityToGetPromoPrice() + ") " + MoneyDisplayUtil.formatMoneyDisplay(promoInfo.getTotalPriceForQuantityMet()));
     }
     Console.WriteLine("\t" + item.PromotionInfo.getPromoDisplayInfo());
     Console.WriteLine("\tsavings " + MoneyDisplayUtil.formatMoneyDisplay(item.PromotionInfo.getSavings()));
 }
Ejemplo n.º 3
0
        public void addItem(GroceryItemData groceryItem)
        {
            Boolean found = false;

            foreach (GroceryItemData item in items)
            {
                if (item.Name.Equals(groceryItem.Name))
                {
                    item.addToQuantity(1);
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                this.items.Add(groceryItem);
            }
        }
        public static Dictionary <String, GroceryItemData> getNameToGroceryItemDataMap(string[] file)
        {
            Dictionary <String, GroceryItemData> nameToGroceryItemDataMap = new Dictionary <String, GroceryItemData> ();

            foreach (string line in file)
            {
                //line ie. item=banana; regularPrice=2,000.7; promoCode=2; quantityRequired=1; promoPrice=2.1
                if (isValidLine(line))
                {
                    cleanLine(line);
                    List <String> subParts     = new List <String>(line.Split(seperator1));
                    String        name         = getItemName(subParts);
                    decimal?      regularPrice = getPrice(subParts, "regularPrice");
                    if (name != null && regularPrice != null)
                    {
                        GroceryItemData groceryItem;
                        if (!nameToGroceryItemDataMap.ContainsKey(name))
                        {
                            groceryItem = new GroceryItemData(name, (decimal)regularPrice);
                            nameToGroceryItemDataMap.Add(groceryItem.Name, groceryItem);
                        }
                        else
                        {
                            groceryItem = nameToGroceryItemDataMap [name];
                            groceryItem.RegularPrice = (decimal)regularPrice;
                        }
                        int?promoCode = getInt(subParts, "promoCode");
                        if (promoCode != null)
                        {
                            groceryItem.setPromotionInfo((int)promoCode, getPrice(subParts, "promoPrice"), getInt(subParts, "quantityRequired"));
                        }
                    }
                }
            }
            return(nameToGroceryItemDataMap);
        }
Ejemplo n.º 5
0
 private static void displayMultipleRegularPricedItem(GroceryItemData item)
 {
     Console.WriteLine(item.Name + " (X" + item.Count + ") " + MoneyDisplayUtil.formatMoneyDisplay(item.RegularPrice * item.Count));
     Console.WriteLine("\t @ " + MoneyDisplayUtil.formatMoneyDisplay(item.RegularPrice) + " each");
 }