Beispiel #1
0
        public decimal BillShopper(Shopper shopper)
        {
            // LINQ, we will learn more of this later
            // arrow function: param => some logic
            // .Sum runs a loop over the list that is to the left of .Sum and executes the arrow function for each item, passing the item to the arrow function's parameter
            decimal totalBill = shopper.ShoppingCart.Sum(prod => prod.Price * prod.Quantity);

            Console.WriteLine($"{Name} has billed ${shopper.Name} ${totalBill}.");
            return(totalBill);
        }
Beispiel #2
0
        public void ShopperExiting(Shopper shopper)
        {
            int idx = shoppers.IndexOf(shopper);

            if (idx > -1)
            {
                shoppers.RemoveAt(idx);
            }
            Console.WriteLine($"Goodbye {shopper.Name}, thank you for shopping at {Name}.");
            PrintCurrentShoppers();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            /*
             *  [x] Create a few grocery stores
             *  [x] Create a few shoppers
             *  [x] Have shoppers enter stores of their choosing
             *      [x] when shopper enters store, store should print a greeting
             *  [x] Have store print list of shoppers
             *  [x] Shoppers have a shopping list
             *  [x] Add items from shoppers list to their cart
             *      [x] print shopping cart items
             *  [x] Shopper checkout and pay
             *      [x] shopper must have enough money
             *          [x] shopper says they got too many items if not enough money
             *      [x] shopper exits store after checkout
             *      [x] store prints goodbye to shopper
             *      [x] store should print list of shopper names
             */
            // DataType varName = value of var
            GroceryStore albertsons = new GroceryStore("Albert And His Beautiful Sons");

            List <Product> shoppingList1 = new List <Product>()
            {
                new Product("Toilet Paper", 5),
                new Product("Healing Crystal", 3),
                new Product("How To Get Gud At LoL, For Dummies and Noobs", 1),
                new Product("Lysol", 3)
            };

            List <Product> shoppingList2 = new List <Product>()
            {
                new Product("Fruit Flavored Chews With 0% Fruit", 8),
                new Product("Wasabi Peas", 2),
                new Product("Meat", 4)
            };

            List <Product> shoppingList3 = new List <Product>()
            {
                new Product("Cactus Jerky", 2),
                new Product("Pineapple Pizza", 4),
                new Product("Egg", 4)
            };

            Shopper shopper1 = new Shopper("Dustin", shoppingList1, 250m);
            Shopper shopper2 = new Shopper("Dallas", shoppingList3, 30m);

            shopper1.EnterStore(albertsons);
            shopper2.EnterStore(albertsons);
            shopper1.Checkout();
            shopper2.Checkout();
        }
Beispiel #4
0
 private void GreetShopper(Shopper shopper)
 {
     Console.WriteLine($"Welcome {shopper.Name} to {Name}");
 }
Beispiel #5
0
 public void ShopperEntering(Shopper shopper)
 {
     shoppers.Add(shopper);
     GreetShopper(shopper);
     PrintCurrentShoppers();
 }