Пример #1
0
 static private bool CheckIfItemExists(String ItemName)
 {
     // If item exists in the catalog return true otherwise false
     if (PriceCatalog.getItemFromName(ItemName) != null)
     {
         return(true);
     }
     Console.WriteLine("Item does not exist in price catalog: " + ItemName);
     return(false);
 }
Пример #2
0
        static public Item CreateItem(String Parameters)
        {
            // Parameters should be one line from the catalog file unsplit and not error checked
            String[] seperator = { "," };
            String[] elements  = Parameters.Split(seperator, StringSplitOptions.RemoveEmptyEntries);


            // Not enough parameters to create an item
            if (elements.Length < 2)
            {
                return(null);
            }

            // Item already exists duplicates not allowed
            if (null != PriceCatalog.getItemFromName(elements[0].ToLower()))
            {
                ErrorHandling.DisplyError("Item already exists: " + elements[0]);
                return(null);
            }

            // Extract the price from the string parameters
            double d;

            if (!double.TryParse(elements[1], out d))
            {
                ErrorHandling.DisplyError("Failed to parse price (double) from: " + Parameters);
                return(null);
            }

            // If the item has no promotions create it without
            if (elements.Length < 3)
            {
                return(new Item(elements[0], d));
            }
            // If the item has a promotion create it with one
            else if (elements.Length >= 3)
            {
                return(new Item(elements[0], d, Factory.PromotionFactory(elements[2])));
            }

            // Criteria not met to create item
            return(null);
        }
Пример #3
0
        static public void Finish()
        {
            Console.WriteLine("\nPrinting Receipt...\n");

            // Iterate through all the items that are being bought
            foreach (String item in Buying)
            {
                Item i = PriceCatalog.getItemFromName(item);
                Console.WriteLine(item);

                // Display original price
                Console.WriteLine("Regular price: $" + Math.Round(i._Price, 2));

                double price = i._Price;
                if (i.HasPromo())
                {
                    // If there is a dicounted price add that to total instead
                    price = i._Promo.CalculatedDiscountedPrice(i._Price);
                    if (price != i._Price)
                    {
                        // Display savings
                        Console.WriteLine("Special pricing: $" + Math.Round(price, 2));
                        Console.WriteLine("You saved: $" + Math.Round((i._Price - price), 2));
                    }
                }

                // Add to total cost
                TotalPrice += price;
            }

            // Display total
            Console.WriteLine("Total: $" + Math.Round(TotalPrice, 2));

            // Thank the customer
            Console.WriteLine("Thank you, please come again.\n");

            Clear();
        }