Exemplo n.º 1
0
        /// <summary>
        /// Finding products with more ingredients than a given number
        /// </summary>
        /// <param name="numerous">Defined amount of ingredients</param>
        /// <returns>Array Bakery with suitable products</returns>
        public Bakery[] FindMoreIngridients(int numerous)
        {
            Bakery[] need_bakers = new Bakery[bakers.Length];

            int j = 0;

            for (int i = 0; i < bakers.Length; i++)
            {
                if (bakers[i].NumerousIngridients(numerous))
                {
                    need_bakers[j] = bakers[i];
                    j++;
                }
            }

            return(need_bakers);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finding products for which the use of ingredients is greater
        /// than the specified value
        /// </summary>
        /// <param name="name_ingridient">Name ingridients entered user</param>
        /// <param name="volume">Weight entered user</param>
        /// <returns>Array Bakery with suitable products</returns>
        public Bakery[] FindBigVolume(string name_ingridient, double volume)
        {
            Bakery[] need_bakers = new Bakery[bakers.Length];

            int j = 0;

            for (int i = 0; i < bakers.Length; i++)
            {
                if (bakers[i].ComparisonVolume(name_ingridient, volume))
                {
                    need_bakers[j] = bakers[i];
                    j++;
                }
            }

            return(need_bakers);
        }
        /// <summary>
        /// Creating an object of the required class
        /// </summary>
        /// <param name="mas">Array with data about object</param>
        /// <param name="name">Name object</param>
        /// <param name="numerous">Numerous object</param>
        /// <returns>Object type Bakery</returns>
        public Bakery MakeObject(string[] mas, string name, int numerous)
        {
            Bakery bakery = null;
            double volume, price, calorie;

            volume  = Total(1, mas);
            price   = Total(2, mas);
            calorie = Total(3, mas);

            switch (name)
            {
            case "Лаваш":
                bakery = new Lavash(mas, volume, price, calorie, numerous);
                break;

            case "Хлеб 'Бородинский'":
                bakery = new Bread(mas, volume, price, calorie, numerous);
                break;

            case "Булка":
                bakery = new Bun(mas, volume, price, calorie, numerous);
                break;

            case "Батон":
                bakery = new Loaf(mas, volume, price, calorie, numerous);
                break;

            case "Багет":
                bakery = new Baget(mas, volume, price, calorie, numerous);
                break;

            case "Бублик":
                bakery = new Bublic(mas, volume, price, calorie, numerous);
                break;

            case "Хлеб ржаной":
                bakery = new BreadRye(mas, volume, price, calorie, numerous);
                break;

            default:
                break;
            }
            return(bakery);
        }
        /// <summary>
        /// 2D array processing and object creation(via factory method)
        /// </summary>
        /// <param name="general_mas">2D array consist words</param>
        /// <param name="count">Numerous object</param>
        /// <returns>Array bakery objects</returns>
        private Bakery[] CutStrok(string[][] general_mas, int count)
        {
            Fabrics fabric = new Fabrics();

            Bakery[] bakers = new Bakery[count];
            string[] mas;

            int start = 0;
            int end   = 0;
            int x;

            for (int i = 0; i < count; i++)
            {
                if (end + 1 != general_mas.Length)
                {
                    end++;
                }
                while (end < general_mas.Length && general_mas[end].Length != 2)
                {
                    end++;
                }

                mas = new string[(end - start - 1) * 4];
                x   = 0;

                string name     = general_mas[start][0];
                int    numerous = Convert.ToInt32(Regex.Replace(
                                                      general_mas[start][1], @"[^\d]", ""));

                start++;
                while (start < end)
                {
                    mas[x]     = general_mas[start][0].Trim();
                    mas[x + 1] = general_mas[start][1];
                    mas[x + 2] = general_mas[start][2];
                    mas[x + 3] = general_mas[start][3];
                    x         += 4;
                    start++;
                }

                bakers[i] = fabric.MakeObject(mas, name, numerous);
            }
            return(bakers);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Copy Bakery array and it is sorted by price (ascending)
        /// </summary>
        /// <returns>Sorted array</returns>
        public Bakery[] CopySortPrice()
        {
            Bakery[] CopyBakery = new Bakery[bakers.Length];
            Array.Copy(bakers, 0, CopyBakery, 0, bakers.Length);

            Bakery tmp;
            int    len = bakers.Length;

            for (int i = 0; i < CopyBakery.Length - 1; i++)
            {
                for (int j = 0; j < len - 1; j++)
                {
                    if (CopyBakery[j].Price > CopyBakery[j + 1].Price)
                    {
                        tmp               = CopyBakery[j];
                        CopyBakery[j]     = CopyBakery[j + 1];
                        CopyBakery[j + 1] = tmp;
                    }
                }
                len--;
            }

            return(CopyBakery);
        }