Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Shape[] array_of_shapes = new Shape[3];
            array_of_shapes[0] = new Circle(4, 6, 2.0);
            array_of_shapes[1] = new Rectangle(14, 25);
            array_of_shapes[2] = new Cylinder(16, 22);

            Console.WriteLine("For what shape you want to calculate the Area:\n0. Circle\n1. Rectangle\n2. Cylinder");
            int choice = int.Parse(Console.ReadLine());

            switch (choice)
            {
            case 0:
                break;

            case 1:
                break;

            case 2:
                break;

            default:
                break;
            }
            if (choice == 0)
            {
                Console.Write("Enter a radius: ");
                int rad = Convert.ToInt16(Console.ReadLine());
                array_of_shapes[choice] = new Circle(0, 0, rad);
            }
            else if (choice == 1)
            {
            }
            else if (choice == 2)
            {
            }
            //for (int i = 0; i < array_of_shapes.Length; i++)
            //{
            Console.WriteLine(" The shape you chose " + choice + " is a " + array_of_shapes[choice].Name + " with volume = "
                              + array_of_shapes[choice].Volume + " and area " + array_of_shapes[choice].Area);
            //}
            Console.Read();
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            //create a new instance of a cuboid, and pass it in the parameters for it's dimensions
            var cuboid = new Cuboid(10, 10, 10);

            //render the cuboid
            cuboid.render();

            //create a new cylinder and give it some dimensions
            var cylinder = new Cylinder(30, 10);

            //render the details of the cylinder
            cylinder.render();

            //create a sphere and pass in the radius
            var sphere = new Sphere(30);

            //render the sphere's details.
            sphere.render();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Box container = new Box(40);

            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(320, 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()}");
            }
        }
Ejemplo n.º 4
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}");
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //Set Points
            var A = new Point(0, 0);
            var B = new Point(3, 4);
            var C = new Point(1.5, 5);
            var D = new Point(1, 2);

            //Distance between points
            var ab = new Distance(A, B);
            var bc = new Distance(B, C);
            var cd = new Distance(C, D);
            var da = new Distance(D, A);

            //Unit explanation
            UnitExplanation.Units();

            //Triangle test
            //var iso = TriangleType.Isosceles;
            //var rect = TriangleType.Rectangular;
            //var obt = TriangleType.Obtuse;
            //var equi = TriangleType.Echilateral;
            var t1 = new TriangleWithSides(A, B, C);
            var t2 = new TriangleWithSides(3, 4, 5);
            var t3 = new TriangleWithSides(1.5, 3.7, 5);
            var t4 = new TriangleWithAngle(3, 3, 45);
            var t5 = new TriangleWithAngle(A, B, C);
            var t6 = new TriangleWithAngle(3, 4, 90);

            t1.Draw();
            t1.DisplayShape();
            t2.DisplayShape();
            t3.DisplayShape();
            t4.DisplayShape();
            t5.DisplayShape();
            t6.DisplayShape();

            //Circle Test
            var circle1 = new Circle(A, B);
            var circle2 = new Circle(3);

            circle1.Draw();
            circle1.DisplayShape();
            circle2.DisplayShape();

            //Rectangle test
            var rect1 = new Rectangle(A, B, D);
            var rect2 = new Rectangle(3, 4);

            rect1.Draw();
            rect1.DisplayShape();
            rect2.DisplayShape();

            //Square test
            var sq1 = new Square(4);
            var sq2 = new Square(A, B);

            sq1.Draw();
            sq1.DisplayShape();
            sq2.DisplayShape();

            //Cylinder test
            var cyl1 = new Cylinder(A, B, C);
            var cyl2 = new Cylinder(3, 5);

            cyl1.Draw();
            cyl1.DisplayShape();
            cyl2.DisplayShape();

            //Sphere test
            var sphere1 = new Sphere(A, B);
            var sphere2 = new Sphere(7.5);

            sphere1.Draw();
            sphere1.DisplayShape();
            sphere2.DisplayShape();

            //Hemisphere test
            var hs1 = new Hemisphere(B, D);
            var hs2 = new Hemisphere(3.7);

            hs1.Draw();
            hs1.DisplayShape();
            hs2.DisplayShape();

            //Cone test
            var cone1 = new Cones(A, B, C);
            var cone2 = new Cones(2.5, 4, 5);

            cone1.Draw();
            cone1.DisplayShape();
            cone2.DisplayShape();

            //Cuboid test
            var cub1 = new Cuboid(5.0, 6.0, 7.0);
            var cub2 = new Cuboid(A, B, C, D);

            cub1.Draw();
            cub1.DisplayShape();
            cub2.DisplayShape();

            //Testing Cube
            var cube1 = new Cube(5);
            var cube2 = new Cube(A, B);

            cube1.Draw();
            cube1.DisplayShape();
            cube2.DisplayShape();
            Display();
            var shapes = new List <Shape>();

            shapes.Add(cub1);
            shapes.Add(cone1);
            shapes.Add(t1);
            shapes.Add(rect1);
            foreach (var item in shapes)
            {
                item.Draw();
            }
        }