Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Supermarket[] product = new Supermarket[] { new Supermarket("chips", 7.00), new Supermarket("soda", 8.50), new Supermarket("juice", 3.00),
                                                        new Supermarket("coffee", 2.50), new Supermarket("tea", 4.00) };
            Supermarket a = new Supermarket();

            Supermarket[] newList = new Supermarket[product.Length + 1];
            Supermarket   b       = new Supermarket("cheese", 7.45);

            double totalPrice = a.CalculateTotalPrice(product);

            Console.Write("The total price is {0}\n", totalPrice);

            Supermarket min = a.FindCheapest(product);

            Console.Write("The cheapest product is {0} with price of {1} \n", min.product, min.price);

            a.RemoveMostExpensive(ref product);
            for (int i = 0; i < product.Length; i++)
            {
                Console.Write(" {0} ", product[i].product);
            }

            newList = a.AddNewProduct(ref product, b);
            for (int i = 0; i < product.Length; i++)
            {
                Console.Write("\n {0} ", product[i].product);
            }

            double avgPrice = a.CalculateAveragePrice(product);

            Console.Write("\nThe average price is {0}\n", avgPrice);
        }
Ejemplo n.º 2
0
        private Supermarket FindCheapest(Supermarket[] product)
        {
            Supermarket min = product[0];

            for (int i = 1; i < product.Length; i++)
            {
                if (min.price > product[i].price)
                {
                    min = product[i];
                }
            }
            return(min);
        }
Ejemplo n.º 3
0
 private Supermarket[] AddNewProduct(ref Supermarket[] shoppingList, Supermarket product)
 {
     Array.Resize(ref shoppingList, shoppingList.Length + 1);
     shoppingList[shoppingList.Length - 1] = product;
     return(shoppingList);
 }