Esempio n. 1
0
        static void Main(string[] args)
        {
            Creator[] variants = new Creator[3];

            variants[0] = new CandyElementCreator();
            variants[1] = new ChokoElementCreator();
            variants[2] = new WaffleElementCreator();

            //  Имя | Вес | Сахар | Калории | Тип элемента

            IGift gift = new Gift.Gift();

            gift.Add(variants[0].Build("Конфета Мишка", 10, 15, 20, TypeCandyElement.ChocolateCandy));
            gift.Add(variants[0].Build("Конфета Мишка1", 11, 13, 5, TypeCandyElement.Sweetmeat));
            gift.Add(variants[0].Build("Конфета1", 8, 13, 1, TypeCandyElement.DropCandy));

            gift.Add(variants[1].Build("Milkа", 100, 13, 210, TypeChocoElement.MilkChocolate));

            gift.Add(variants[2].Build("Вафля cream", 110, 15, 20, TypeWaffleElement.CreamyWafer));
            gift.Add(variants[2].Build("Вафля komunarka", 170, 14, 22, TypeWaffleElement.ChocolateWaffle));

            Console.WriteLine(new string('-', 75));
            gift.ToConsole();

            Console.WriteLine("Итого масса:              {0} гр.", gift.GiftWeight());
            Console.WriteLine("Калорий во всем подарке:  {0}.", gift.GiftSumCalories());
            Console.WriteLine(new string('-', 75));

            Console.WriteLine("SortByWeight:");
            gift.SortByWeight();
            gift.ToConsole();

            Console.WriteLine("SortByCalorie:");
            gift.SortByCalorie();
            gift.ToConsole();

            Console.WriteLine("FindBySugar:");
            gift.FindBySugar(0, 14);
            gift.ToConsole();

            //gift.SortByName();
            //gift.ToConsole();

            SplitText.Go();
        }
Esempio n. 2
0
        public static void Go()
        {
            string[] lines = System.IO.File.ReadAllLines(@"C:\Lines.txt");

            Creator[] variants = new Creator[3];
            variants[0] = new CandyElementCreator();
            variants[1] = new ChokoElementCreator();
            variants[2] = new WaffleElementCreator();
            IGift gift = new Gift.Gift();

            TypeCandyElement p1, p2, p3;

            Enum.TryParse <TypeCandyElement>("ChocolateCandy", out p1);
            Enum.TryParse <TypeCandyElement>("DropCandy", out p2);
            Enum.TryParse <TypeCandyElement>("Sweetmeat", out p3);
            TypeChocoElement p4, p5, p6;

            Enum.TryParse <TypeChocoElement>("MilkChocolate", out p4);
            Enum.TryParse <TypeChocoElement>("PorousChocolate", out p5);
            Enum.TryParse <TypeChocoElement>("DarkChocolate", out p6);
            TypeWaffleElement p7, p8;

            Enum.TryParse <TypeWaffleElement>("ChocolateWaffle", out p7);
            Enum.TryParse <TypeWaffleElement>("CreamyWafer", out p8);


            foreach (string line in lines)
            {
                Regex.Replace(line, @"\s+", "");           //убрал пробелы

                if (line.Contains("ChocolateCandy"))
                {
                    String[] substrings = line.Split(',');//разделил на  подстроки
                    if (substrings.Length == 5)
                    {
                        gift.Add(variants[0].Build(substrings[0], Int32.Parse(substrings[1]),
                                                   Int32.Parse(substrings[2]), Int32.Parse(substrings[3]), p1));
                    }
                    else
                    {
                        Console.WriteLine("Битая строка!!!");
                    }
                }

                if (line.Contains("DropCandy"))
                {
                    String[] substrings = line.Split(',');
                    if (substrings.Length == 5)
                    {
                        gift.Add(variants[0].Build(substrings[0], Int32.Parse(substrings[1]),
                                                   Int32.Parse(substrings[2]), Int32.Parse(substrings[3]), p2));
                    }
                    else
                    {
                        Console.WriteLine("Битая строка!!!");
                    }
                }

                if (line.Contains("Sweetmeat"))
                {
                    String[] substrings = line.Split(',');
                    if (substrings.Length == 5)
                    {
                        gift.Add(variants[0].Build(substrings[0], Int32.Parse(substrings[1]),
                                                   Int32.Parse(substrings[2]), Int32.Parse(substrings[3]), p3));
                    }
                    else
                    {
                        Console.WriteLine("Битая строка!!!");
                    }
                }

                if (line.Contains("MilkChocolate"))
                {
                    String[] substrings = line.Split(',');
                    if (substrings.Length == 5)
                    {
                        gift.Add(variants[1].Build(substrings[0], Int32.Parse(substrings[1]),
                                                   Int32.Parse(substrings[2]), Int32.Parse(substrings[3]), p4));
                    }
                    else
                    {
                        Console.WriteLine("Битая строка!!!");
                    }
                }

                if (line.Contains("PorousChocolate"))
                {
                    String[] substrings = line.Split(',');
                    if (substrings.Length == 5)
                    {
                        gift.Add(variants[1].Build(substrings[0], Int32.Parse(substrings[1]),
                                                   Int32.Parse(substrings[2]), Int32.Parse(substrings[3]), p5));
                    }
                    else
                    {
                        Console.WriteLine("Битая строка!!!");
                    }
                }

                if (line.Contains("DarkChocolate"))
                {
                    String[] substrings = line.Split(',');
                    if (substrings.Length == 5)
                    {
                        gift.Add(variants[1].Build(substrings[0], Int32.Parse(substrings[1]),
                                                   Int32.Parse(substrings[2]), Int32.Parse(substrings[3]), p6));
                    }
                    else
                    {
                        Console.WriteLine("Битая строка!!!");
                    }
                }

                if (line.Contains("ChocolateWaffle"))
                {
                    String[] substrings = line.Split(',');
                    if (substrings.Length == 5)
                    {
                        gift.Add(variants[2].Build(substrings[0], Int32.Parse(substrings[1]),
                                                   Int32.Parse(substrings[2]), Int32.Parse(substrings[3]), p7));
                    }
                    else
                    {
                        Console.WriteLine("Битая строка!!!");
                    }
                }

                if (line.Contains("CreamyWafer"))
                {
                    String[] substrings = line.Split(',');
                    if (substrings.Length == 5)
                    {
                        gift.Add(variants[2].Build(substrings[0], Int32.Parse(substrings[1]),
                                                   Int32.Parse(substrings[2]), Int32.Parse(substrings[3]), p8));
                    }
                    else
                    {
                        Console.WriteLine("Битая строка!!!");
                    }
                }
            }

            Console.WriteLine("--------FROM FILE!! ------>");
            gift.ToConsole();

            //gift.SortByWeight();
            //gift.SortByName();
            //gift.ToConsole();
        }