コード例 #1
0
        public static void ParseFile(CollectionType <Plant> objColl)
        {
            using (StreamReader stream = new StreamReader(@"E:\ООП\Lab_5\Lab_5\5_lab.txt"))
            {
                while (stream.ReadLine() is string line)
                {
                    switch (line)
                    {
                    case "Rose": objColl.Add(new Rose());
                        break;

                    case "Bush": objColl.Add(new Bush());
                        break;

                    case "Gladiolus": objColl.Add(new Gladiolus());
                        break;

                    case "Cactus": objColl.Add(new Cactus());
                        break;
                    }
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: NastyaLig/OOP3-sem
        static void Main(string[] args)
        {
            Console.WriteLine("-----------Розы-------------");
            Rose rose = new Rose();

            rose.ToPlant();
            rose.GetPlants();
            rose.ToPlant();
            rose.ToPlant();
            rose.GetPlants();
            rose.Pour(3);
            if (rose is Plant)
            {
                Console.WriteLine($"{rose} is plant");
            }

            Console.WriteLine("-----------Кактусы-------------");
            Cactus cactus   = new Cactus();
            IPot   cactus_2 = cactus;

            cactus_2.ToPlant();
            cactus.ToPlant();
            cactus.GetPlants();
            cactus.Collect();
            cactus.PutInPot();

            Console.WriteLine("-----------Гладиолусы-------------");
            Gladiolus gladiolus = new Gladiolus();

            gladiolus.ToPlant();
            gladiolus.ToPlant();
            gladiolus.Pour(2);
            gladiolus.Collect();
            gladiolus.PackIn();

            Printer printer = new Printer();

            printer.iAmPrinting(cactus);

            CollectionType <string> obj1 = new CollectionType <string>();
            IGereric <string>       a;

            obj1.Add("bye ");
            obj1.Add("adyos ");
            obj1.Add("sayonara ");
            a = obj1;
            a.Show();

            CollectionType <Plant> plnt = new CollectionType <Plant>();

            plnt.Add(new Rose());
            plnt.Add(new Gladiolus());
            plnt.Add(new Bush());
            plnt.Show();

            Console.WriteLine("\n");
            CollectionType <Plant> obj2 = new CollectionType <Plant>();

            ParseFile(obj2);
            obj2.Show();

            obj2.WriteFile(obj2);
        }