Ejemplo n.º 1
0
        public void Decommissione()
        {
            Product  product;
            int      iter = 0;
            DateTime temp;
            int      pastDueMilk      = 0;
            int      pastDueBread     = 0;
            int      pastDueCake      = 0;
            int      pastDueChocolate = 0;

            int pastDueMeat        = 0;
            int pastDueSausage     = 0;
            int pastDueToiletPaper = 0;
            int sum = 0;

            for (DateTime start = dataStart; ; iter++)
            {
                temp = start.AddDays(iter);
                if (temp.CompareTo(dataToday) == 0)
                {
                    break;
                }
                for (int i = 0; i < products.Count; i++)
                {
                    //////////// Milk  ////////////////////
                    if (products[i] is Milk)
                    {
                        int days = ((Milk)products[i]).shelfLife;

                        if (((Milk)products[i]).dateOfManufacture.AddDays(days) < temp)
                        {
                            //Console.WriteLine(((Milk)products[i]).dateOfManufacture + "   Milk");
                            products.RemoveAt(i);
                            pastDueMilk++;
                        }
                    }
                    //////////// Bread  ////////////////////
                    if (products[i] is Bread)
                    {
                        int days = ((Bread)products[i]).shelfLife;

                        if (((Bread)products[i]).dateOfManufacture.AddDays(days) < temp)
                        {
                            //Console.WriteLine(((Bread)products[i]).dateOfManufacture + "   Bread");
                            products.RemoveAt(i);
                            pastDueBread++;
                        }
                    }
                    //////////// Cake  ////////////////////
                    if (products[i] is Cake)
                    {
                        int days = ((Cake)products[i]).shelfLife;

                        if (((Cake)products[i]).dateOfManufacture.AddDays(days) < temp)
                        {
                            //Console.WriteLine(((Cake)products[i]).dateOfManufacture + "   Cake");
                            products.RemoveAt(i);
                            pastDueCake++;
                        }
                    }

                    //////////// Chocolate  ////////////////////
                    if (products[i] is Chocolate)
                    {
                        int days = ((Chocolate)products[i]).shelfLife;

                        if (((Chocolate)products[i]).dateOfManufacture.AddDays(days) < temp)
                        {
                            //Console.WriteLine(((Chocolate)products[i]).dateOfManufacture + "   Chocolate");
                            products.RemoveAt(i);
                            pastDueChocolate++;
                        }
                    }

                    //////////// Meat  ////////////////////
                    if (products[i] is Meat)
                    {
                        int days = ((Meat)products[i]).shelfLife;

                        if (((Meat)products[i]).dateOfManufacture.AddDays(days) < temp)
                        {
                            //Console.WriteLine(((Meat)products[i]).dateOfManufacture + "   Meat");
                            products.RemoveAt(i);
                            pastDueMeat++;
                        }
                    }

                    //////////// Meat  ////////////////////
                    if (products[i] is Sausage)
                    {
                        int days = ((Sausage)products[i]).shelfLife;

                        if (((Sausage)products[i]).dateOfManufacture.AddDays(days) < temp)
                        {
                            //Console.WriteLine(((Sausage)products[i]).dateOfManufacture + "   Sausage");
                            products.RemoveAt(i);
                            pastDueSausage++;
                        }
                    }

                    //////////// ToiletPaper  ////////////////////
                    if (products[i] is ToiletPaper)
                    {
                        int days = ((ToiletPaper)products[i]).shelfLife;

                        if (((ToiletPaper)products[i]).dateOfManufacture.AddDays(days) < temp)
                        {
                            //Console.WriteLine(((ToiletPaper)products[i]).dateOfManufacture + "   ToiletPaper");
                            products.RemoveAt(i);
                            pastDueToiletPaper++;
                        }
                    }
                }
                if (temp.DayOfWeek == DayOfWeek.Sunday)
                {
                    Console.WriteLine("[From " + temp.AddDays(-6).ToString("dddd, dd MMMM yyyy") + "] to [" + temp.ToString("dddd, dd MMMM yyyy") + "] was decommissioned:");


                    if (pastDueMilk > 0)
                    {
                        product = new Milk();
                        Console.WriteLine(pastDueMilk + " " + ((Milk)product).name + " " + (((Milk)product).Price) * pastDueMilk + " (UAH)");

                        sum        += (((Milk)product).Price) * pastDueMilk;
                        pastDueMilk = 0;
                    }

                    if (pastDueBread > 0)
                    {
                        product = new Bread();
                        Console.WriteLine(pastDueBread + " " + ((Bread)product).name + " " + (((Bread)product).Price) * pastDueBread + " (UAH)");

                        sum         += (((Bread)product).Price) * pastDueBread;
                        pastDueBread = 0;
                    }

                    if (pastDueCake > 0)
                    {
                        product = new Cake();
                        Console.WriteLine(pastDueCake + " " + ((Cake)product).name + " " + (((Cake)product).Price) * pastDueCake + " (UAH)");

                        sum        += (((Cake)product).Price) * pastDueCake;
                        pastDueCake = 0;
                    }

                    if (pastDueChocolate > 0)
                    {
                        product = new Chocolate();
                        Console.WriteLine(pastDueCake + " " + ((Chocolate)product).name + " " + (((Chocolate)product).Price) * pastDueChocolate + " (UAH)");

                        sum += (((Chocolate)product).Price) * pastDueChocolate;
                        pastDueChocolate = 0;
                    }

                    if (pastDueMeat > 0)
                    {
                        product = new Meat();
                        Console.WriteLine(pastDueMeat + " " + ((Meat)product).name + " " + (((Meat)product).Price) * pastDueMeat + " (UAH)");

                        sum        += (((Meat)product).Price) * pastDueMeat;
                        pastDueMeat = 0;
                    }

                    if (pastDueSausage > 0)
                    {
                        product = new Sausage();
                        Console.WriteLine(pastDueSausage + " " + ((Sausage)product).name + " " + (((Sausage)product).Price) * pastDueSausage + " (UAH)");

                        sum           += (((Sausage)product).Price) * pastDueSausage;
                        pastDueSausage = 0;
                    }

                    if (pastDueToiletPaper > 0)
                    {
                        product = new ToiletPaper();
                        Console.WriteLine(pastDueToiletPaper + " " + ((ToiletPaper)product).name + " " + (((ToiletPaper)product).Price) * pastDueToiletPaper + " (UAH)");

                        sum += (((ToiletPaper)product).Price) * pastDueToiletPaper;
                        pastDueToiletPaper = 0;
                    }
                    Console.WriteLine("Total weekly loss:" + sum + " (UAH)");
                    sum = 0;
                    Console.WriteLine("-----------------------------------------------------------------------");
                }
            }
        }
Ejemplo n.º 2
0
        public void showFreshProducts()
        {
            Product product;
            int     countMilk        = 0;
            int     countBread       = 0;
            int     countCake        = 0;
            int     countChocolate   = 0;
            int     countMeat        = 0;
            int     countSausage     = 0;
            int     countToiletPaper = 0;

            Console.WriteLine("Today we have such fresh products:");

            for (int i = 0; i < products.Count; i++)
            {
                if (products[i] is Bread)
                {
                    //Console.WriteLine( ((Bread)products[i]).name);
                    countBread++;
                }
                if (products[i] is Cake)
                {
                    //Console.WriteLine(((Cake)products[i]).name);
                    countCake++;
                }
                if (products[i] is Chocolate)
                {
                    //Console.WriteLine(((Chocolate)products[i]).name);
                    countChocolate++;
                }
                if (products[i] is Meat)
                {
                    //Console.WriteLine(((Meat)products[i]).name);
                    countMeat++;
                }
                if (products[i] is Milk)
                {
                    //Console.WriteLine(((Milk)products[i]).name);
                    countMilk++;
                }
                if (products[i] is Sausage)
                {
                    //Console.WriteLine(((Sausage)products[i]).name);
                    countSausage++;
                }
                if (products[i] is ToiletPaper)
                {
                    //Console.WriteLine(((ToiletPaper)products[i]).name);
                    countToiletPaper++;
                }
            }
            product = new Milk();
            Console.WriteLine(countMilk + " - " + ((Milk)product).name + " ---------- " + ((Milk)product).Price + " (UAH)");

            product = new Bread();
            Console.WriteLine(countBread + " - " + ((Bread)product).name + " --------- " + ((Bread)product).Price + " (UAH)");

            product = new Cake();
            Console.WriteLine(countCake + " - " + ((Cake)product).name + " --------- " + ((Cake)product).Price + " (UAH)");

            product = new Chocolate();
            Console.WriteLine(countChocolate + " - " + ((Chocolate)product).name + " ----- " + ((Chocolate)product).Price + " (UAH)");

            product = new Meat();
            Console.WriteLine(countMeat + " - " + ((Meat)product).name + " --------- " + ((Meat)product).Price + " (UAH)");

            product = new Sausage();
            Console.WriteLine(countSausage + " - " + ((Sausage)product).name + " ------ " + ((Sausage)product).Price + " (UAH)");

            product = new ToiletPaper();
            Console.WriteLine(countToiletPaper + " - " + ((ToiletPaper)product).name + " -- " + ((ToiletPaper)product).Price + " (UAH)");
        }