예제 #1
0
        static void Main(string[] args)
        {
            try
            {
                Box container = new Box(30);

                var shapes = new List <Shape>();

                Box box = new Box(20);
                shapes.Add(box);

                Cylinder cylinder = new Cylinder(30, 10);
                shapes.Add(cylinder);

                Ball ball = new Ball(15);
                shapes.Add(ball);

                Pyramid pyramid = new Pyramid(3200, 10);
                shapes.Add(pyramid);

                Console.WriteLine($"Объём контейнера: {container.Volume()}");

                foreach (var shape in shapes)
                {
                    if (!container.Add(shape))
                    {
                        Console.WriteLine("Контейнер заполнен!\nВ контейнере находятся фигуры:\n");
                        foreach (var shp in container.Shapes)
                        {
                            Console.WriteLine($"{shp.Name} объёмом {shp.Volume()}");
                        }

                        break;
                    }

                    Console.WriteLine($"В контейнер добавлена фигура {shape.Name}" +
                                      $"\nОставшийся объём {container.RemainingVolume()}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Произошла трагическая ошибка: {ex.Message}");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            bool containerIsCreated = false;
            Box  container          = new Box(0);

            while (true)
            {
                try
                {
                    Console.WriteLine("Menu: \n" +
                                      "1. Create container\n" +
                                      "2. Add figure in container\n" +
                                      "0. Exit");
                    switch (Console.ReadLine())
                    {
                    case "1":
                    {
                        if (containerIsCreated)
                        {
                            container.listOfShape.Clear();
                        }
                        Console.WriteLine("Input height container:");
                        double heigthBox = double.Parse(Console.ReadLine());
                        container = new Box(heigthBox);
                        Console.WriteLine($"Box created. Volume container {container.Volume()}");
                        containerIsCreated = true;
                        break;
                    }

                    case "2":
                    {
                        Console.Clear();
                        Console.WriteLine("Choose Shape:\n" +
                                          "1.Cylinder\n" +
                                          "2.Pyramid\n" +
                                          "3.Ball\n" +
                                          "4.Box ");
                        switch (Console.ReadLine())
                        {
                        case "1":
                        {
                            Console.WriteLine("Input radius: ");
                            double radius = double.Parse(Console.ReadLine());
                            Console.WriteLine("Input heigth: ");
                            double   heigth   = double.Parse(Console.ReadLine());
                            Cylinder cylinder = new Cylinder(radius, heigth);
                            if (container.Add(cylinder))
                            {
                                WhatInBox(container);
                            }
                            else
                            {
                                Console.WriteLine("Figure over size!");
                            }
                            break;
                        }

                        case "2":
                        {
                            Console.WriteLine("Input square: ");
                            double square = double.Parse(Console.ReadLine());
                            Console.WriteLine("Input heigth: ");
                            double  heigth  = double.Parse(Console.ReadLine());
                            Pyramid pyramid = new Pyramid(square, heigth);
                            if (container.Add(pyramid))
                            {
                                WhatInBox(container);
                            }
                            else
                            {
                                Console.WriteLine("Figure over size!");
                            }
                            break;
                        }

                        case "3":
                        {
                            Console.WriteLine("Input radius: ");
                            double radius = double.Parse(Console.ReadLine());
                            Ball   ball   = new Ball(radius);
                            if (container.Add(ball))
                            {
                                WhatInBox(container);
                            }
                            else
                            {
                                Console.WriteLine("Figure over size!");
                            }
                            break;
                        }

                        case "4":
                        {
                            Console.WriteLine("Input heigth: ");
                            double heigth = double.Parse(Console.ReadLine());
                            Box    box    = new Box(heigth);
                            if (container.Add(box))
                            {
                                WhatInBox(container);
                            }
                            else
                            {
                                Console.WriteLine("Figure over size!");
                            }
                            break;
                        }
                        }
                        break;
                    }

                    case "0":
                    {
                        return;
                    }

                    default:
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Fatal Error: { e.Message}");
                }
            }
        }