Example #1
0
        static void Main(string[] args)
        {
            IShape[] shapes = { new Square(2),  new Triangle(1, 1,  2,  2,  3, 1), new Rectangle(2, 3), new Circle(3),
                                new Square(15), new Triangle(3, 3, 10, 10, 12, 2), new Rectangle(5, 7), new Circle(7),
                                new Square(7),  new Triangle(0, 0,  7, 15, 14, 0), new Rectangle(6, 2), new Circle(4) };
            Console.WriteLine("Все фигуры:\nТип\t\tШирина\tВысота\tПлощадь\tПериметр\tHashCode");
            foreach (IShape shape in shapes)
            {
                Console.WriteLine("{0}\t\t{1}", shape, shape.GetHashCode());
            }

            GetShapeWithMaxArea(shapes);
            GetShapeWithSecondPerimeter(shapes);

            Square    square    = new Square(2);
            Circle    circle    = new Circle(7);
            Rectangle rectangle = new Rectangle(6, 2);
            Triangle  triangle  = new Triangle(0, 0, 7, 15, 14, 0);

            Console.WriteLine("\nПоиск фигур:");
            Console.WriteLine("Тип\t\tШирина\tВысота\tПлощадь\tПериметр");
            Console.WriteLine(square.ToString());
            Console.WriteLine(circle.ToString());
            Console.WriteLine(rectangle.ToString());
            Console.WriteLine(triangle.ToString());
            Console.WriteLine("\nТип\t\tШирина\tВысота\tПлощадь\tПериметр");
            foreach (IShape shape in shapes)
            {
                if (square.Equals(shape) || circle.Equals(shape) || rectangle.Equals(shape) ||
                    triangle.Equals(shape))
                {
                    Console.WriteLine("{0}\tФигуры равны", shape);
                }
                else
                {
                    Console.WriteLine("{0}\tФигуры не равны", shape);
                }
            }

            Console.WriteLine("Для выхода нажмите Утеук...");
            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            Square    shape1  = new Square(22.5);
            Rectangle shape2  = new Rectangle(35.2, 40);
            Triangle  shape3  = new Triangle(1, 2, 4, 5, 5.5, 1.5);
            Circle    shape4  = new Circle(10);
            Square    shape5  = new Square(60);
            Rectangle shape6  = new Rectangle(15.2, 17);
            Triangle  shape7  = new Triangle(1, 3, 5, 7, 5, 2);
            Circle    shape8  = new Circle(20);
            Circle    shape9  = new Circle(5);
            Square    shape10 = new Square(17);
            Square    shape11 = new Square(17);

            if (shape10.GetHashCode() == shape11.GetHashCode())
            {
                if (shape10.Equals(shape11))
                {
                    Console.WriteLine("Object is equals");
                }
            }
            else
            {
                Console.WriteLine("Object do not equals");
            }

            IShape[] shapes = new IShape[] { shape1, shape2, shape3, shape4, shape5, shape6, shape7, shape8, shape9, shape10 };

            foreach (IShape s in shapes)
            {
                Console.WriteLine("{0}", s.ToString());
            }

            IShape maxFigureArea     = GetShapeArea(shapes);
            IShape seconMaxPerimeter = GetShapePerimeter(shapes);

            Console.WriteLine();
            Console.WriteLine("Figure have max area {0}", maxFigureArea.ToString());
            Console.WriteLine("Figure have second max perimeter {0}", seconMaxPerimeter.ToString());

            Console.ReadKey();
        }