Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            User[] users = new User[2];
            users[0].name = "Swatar";
            users[0].age  = 18;
            users[1].name = "MrWeebeez";
            users[1].age  = 18;

            var clock1  = new Clock(ClockModel.G_shock, "China", "1 year", 59.99F, 20);
            var clock2  = new Clock(ClockModel.ApplWtc, "USA", "5 year", 399.99F, 30);
            var clock3  = new Clock(ClockModel.Mi_Band, "China", "4 year", 149.99F, 40);
            var flower1 = new Flowers(Flower.Rose, "Вкусно", "Italy", "5 days", 5, 4);
            var Lakomka = new Cake("Вкусно", "Belarus", "5 days", 8, 50, 20, 50, 10, 20, 40, 50);
            var gift    = new Gift();


            var products = new Product[5];

            products[0] = clock1;
            products[1] = clock2;
            products[2] = clock3;
            products[3] = flower1;
            products[4] = Lakomka;

            Int32          varint = 0;
            ConsoleKeyInfo info;

            while (varint == 0)
            {
                Console.WriteLine(
                    "Введите функцию, которую хотите выполнить:" +
                    "\n1)Показать информацию о товарах\n2)Чтобы что-нибудь скушать\n3)Кинуть часы(class)\n4)Кинуть часы(interface)\n" +
                    "5)G_shock - это часы?\n6)Типы наших товаров\n7)Работа с подарком на Новый Год\n8)Работа с Экзепшионами\n9)Тест\n0)Выход из программы");

                Console.WriteLine(new string('_', 100));
                info = Console.ReadKey(true);
                if (info.KeyChar == '1')
                {
                    Console.Clear();
                    try
                    {
                        foreach (Product product in products)
                        {
                            product.Info();
                        }
                    }
                    catch
                    {
                        throw new ArgumentOutOfRangeException("Выход за пределы массива");
                    }
                }

                if (info.KeyChar == '2')
                {
                    Console.Clear();
                    Console.WriteLine("1-Часы\n2-Торт\n3-Цветок");
                    Console.WriteLine(new string('_', 100));
                    info = Console.ReadKey(true);
                    if (info.KeyChar == '1')
                    {
                        Console.Clear();
                        clock1.Eat();
                    }
                    if (info.KeyChar == '2')
                    {
                        Console.Clear();
                        Lakomka.Eat();
                    }
                    if (info.KeyChar == '3')
                    {
                        ComAliasNameAttribute a = new ComAliasNameAttribute(alias:);
                    }
                }


                if (info.KeyChar == '4')
                {
                    Console.Clear();
                    ((Ieat)clock2).Throw();
                }

                if (info.KeyChar == '5')
                {
                    Console.Clear();
                    Console.WriteLine("Являются ли часы G_shock_2 часами?");
                    Console.WriteLine(clock2 is Clock);
                    Console.WriteLine(new string('_', 100));
                }

                if (info.KeyChar == '6')
                {
                    Console.Clear();
                    try
                    {
                        foreach (Product produc in products)
                        {
                            Console.WriteLine(produc.ToString());
                        }
                    }
                    catch
                    {
                        throw new ArgumentOutOfRangeException("Выход за пределы массива");
                    }
                    Console.WriteLine(new string('_', 100));
                }

                if (info.KeyChar == '7')
                {
                    Console.WriteLine("1)Добавить подарок\n2)Вывести содержимое подарка\n3)Удаление содержимого из подарка\n4)Стоимость подарка\n5)Самый лёгкий элемент подарка");
                    info = Console.ReadKey(true);
                    Console.Clear();
                    if (info.KeyChar == '1')
                    {
                        Console.Clear();
                        for (Int32 i = 0; i < products.Length; i++)
                        {
                            gift.List.Add(products[i]);
                        }
                        Console.WriteLine("Вещи добавлены");
                        Console.WriteLine(new string('_', 100));
                    }

                    if (info.KeyChar == '2')
                    {
                        for (Int32 i = 0; i < gift.List.Count; i++)
                        {
                            Console.WriteLine(gift.List[i]);
                        }
                        Console.WriteLine(new string('_', 100));
                    }

                    if (info.KeyChar == '3')
                    {
                        Console.WriteLine("1)Удалить ВСЁ\n2)Удалить выбранный элемент");
                        info = Console.ReadKey(true);
                        Console.Clear();
                        if (info.KeyChar == '1')
                        {
                            gift.List.Clear();
                        }
                        if (info.KeyChar == '2')
                        {
                            Int32 elem;
                            Console.WriteLine("Введите индекс элемента, который вы хотите удалить:");
                            while (!Int32.TryParse(Console.ReadLine(), out elem))
                            {
                                Console.Clear();
                                Console.WriteLine("Введите корректное число!");
                            }
                            gift.List.RemoveAt(elem);
                            Console.WriteLine(new string('_', 100));
                        }
                    }

                    if (info.KeyChar == '4')
                    {
                        gift.FinalCoast();
                    }

                    if (info.KeyChar == '5')
                    {
                        gift.MinWeight();
                    }
                }

                if (info.KeyChar == '8')
                {
                    Person p = new Person();
                    try
                    {
                        p = new Person {
                            Name = "Сватар", Age = 17
                        };
                    }
                    catch (AgeException ex)
                    {
                        Console.Clear();
                        Console.WriteLine("Ошибка: " + ex.Message);
                    }
                    finally
                    {
                        Console.WriteLine(new String('_', 100));
                    }
                    Console.WriteLine(p.Name);
                    int[] aa = null;
                    Debug.Assert(aa != null, "Values array cannot be null");
                }

                if (info.KeyChar == '9')
                {
                    string[] str = new string[5];
                    try
                    {
                        str[7] = "anythinddddg";
                        Console.WriteLine("It's OK");
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        Console.WriteLine("IndexOutOfRangeException");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Exception");
                    }
                }

                if (info.KeyChar == '0')
                {
                    Console.Clear();
                    varint++;
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            User[] users = new User[2];
            users[0].name = "Swatar";
            users[0].age  = 18;
            users[1].name = "MrWeebeez";
            users[1].age  = 18;

            Clock   clock1  = new Clock(ClockModel.G_shock, "China", "1 year", 59.99F, 20);
            Clock   clock2  = new Clock(ClockModel.ApplWtc, "USA", "5 year", 399.99F, 30);
            Clock   clock3  = new Clock(ClockModel.Mi_Band, "China", "4 year", 149.99F, 40);
            Flowers flower1 = new Flowers(Flower.Rose, "Вкусно", "Italy", "5 days", 5, 4);
            Cake    Lakomka = new Cake("Вкусно", "Belarus", "5 days", 8, 50, 20, 50, 10, 20, 40, 50);
            Gift    gift    = new Gift();


            Product[] products = new Product[5];
            products[0] = clock1;
            products[1] = clock2;
            products[2] = clock3;
            products[3] = flower1;
            products[4] = Lakomka;

            Int32 varint = 0;

            while (varint == 0)
            {
                Console.WriteLine("Введите функцию, которую хотите выполнить:\n1)Показать информацию о товарах\n2)Чтобы что-нибудь скушать\n3)Кинуть часы(class)\n4)Кинуть часы(interface)\n5)G_shock - это часы?\n6)Типы наших товаров\n7)Работа с подарком на Новый Год\n0)Выход из программы");
                Console.WriteLine(new string('_', 100));
                ConsoleKeyInfo info = Console.ReadKey(true);
                if (info.KeyChar == '1')
                {
                    Console.Clear();
                    foreach (Product product in products)
                    {
                        product.Info();
                    }
                }

                if (info.KeyChar == '2')
                {
                    Console.Clear();
                    Console.WriteLine("1-Часы\n2-Торт\n3-Цветок");
                    Console.WriteLine(new string('_', 100));
                    info = Console.ReadKey(true);
                    if (info.KeyChar == '1')
                    {
                        Console.Clear();
                        clock1.Eat();
                    }
                    if (info.KeyChar == '2')
                    {
                        Console.Clear();
                        Lakomka.Eat();
                    }
                }

                if (info.KeyChar == '3')
                {
                    Console.Clear();
                    clock1.Throw();
                }

                if (info.KeyChar == '4')
                {
                    Console.Clear();
                    clock2.Throw();
                }

                if (info.KeyChar == '5')
                {
                    Console.Clear();
                    Console.WriteLine("Являются ли часы G_shock_2 часами?");
                    Console.WriteLine(clock2 is Clock);
                    Console.WriteLine(new string('_', 100));
                }

                if (info.KeyChar == '6')
                {
                    Console.Clear();
                    foreach (Product produc in products)
                    {
                        Console.WriteLine(produc.ToString());
                    }
                    Console.WriteLine(new string('_', 100));
                }

                if (info.KeyChar == '7')
                {
                    Console.WriteLine("1)Добавить подарок\n2)Вывести содержимое подарка\n3)Удаление содержимого из подарка\n4)Стоимость подарка\n5)Самый лёгкий элемент подарка");
                    info = Console.ReadKey(true);
                    Console.Clear();
                    if (info.KeyChar == '1')
                    {
                        Console.Clear();
                        for (Int32 i = 0; i < products.Length; i++)
                        {
                            gift.List.Add(products[i]);
                        }
                        Console.WriteLine("Вещи добавлены");
                        Console.WriteLine(new string('_', 100));
                    }

                    if (info.KeyChar == '2')
                    {
                        for (Int32 i = 0; i < gift.Count; i++)
                        {
                        }

                        for (Int32 i = 0; i < gift.List.Count; i++)
                        {
                            Console.WriteLine(gift.List[i]);
                        }
                        Console.WriteLine(new string('_', 100));
                    }

                    if (info.KeyChar == '3')
                    {
                        Console.WriteLine("1)Удалить ВСЁ\n2)Удалить выбранный элемент");
                        info = Console.ReadKey(true);
                        Console.Clear();
                        if (info.KeyChar == '1')
                        {
                            gift.List.Clear();
                        }
                        if (info.KeyChar == '2')
                        {
                            Int32 elem;
                            Console.WriteLine("Введите индекс элемента, который вы хотите удалить:");
                            while (!Int32.TryParse(Console.ReadLine(), out elem))
                            {
                                Console.Clear();
                                Console.WriteLine("Введите корректное число!");
                            }
                            Console.WriteLine(new string('_', 100));
                        }
                    }

                    if (info.KeyChar == '4')
                    {
                        gift.FinalCoast();
                    }

                    if (info.KeyChar == '5')
                    {
                        gift.MinWeight();
                    }
                }

                if (info.KeyChar == '0')
                {
                    Console.Clear();
                    varint++;
                }
            }
        }