Exemplo n.º 1
0
        static void Main()
        {
            Rectangle quad = new Rectangle(4, 4);
            Triangle tri = new Triangle(5, 6);

            // double surfaceTri Triangle.CalculateSurface(5, 6); // static

            // Console.WriteLine(quad.CalculateSurface());
            // Console.WriteLine(tri.CalculateSurface());

            Square square = new Square(3.8);
            // Console.WriteLine(square.CalculateSurface());

            Shape[] figures =
            {
                quad,
                tri,
                square,
            };

            foreach (var f in figures)
            {
                Console.WriteLine(f.CalculateSurface());
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            Triangle triangle = new Triangle(1.1, 2.2, 3.3);
            Rectangle rectangle = new Rectangle(2.2, 3.2);
            Circle circle = new Circle(2.2);

            IShape[] figures = { triangle, rectangle, circle };
            foreach (var figure in figures)
            {
                Console.WriteLine("Area of this {0} = {1:0.##}", figure.GetType().Name, figure.CalculateArea());
                Console.WriteLine("Perimeter of this {0} = {1:0.##}", figure.GetType().Name, figure.CalculatePerimeter());
                Console.WriteLine(new string('=', 40));
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //Testing the shapes :
            Shape[] shapes = new Shape[3];
            shapes[0] = new Triangle(5, 5);
            shapes[1] = new Rectangle(10, 10);
            shapes[2] = new Circle(15);

            //Printing on the console:
            foreach (var shape in shapes)
            {
                Console.WriteLine("The surface of the {0} is {1:F2}.",shape.GetType().Name, shape.CalculateSurface());
            }
        }
Exemplo n.º 4
0
        static void Main()
        {
            List<Shape> shapes = new List<Shape>();
            Shape oneSquare = new Square(5);
            Shape anotherSquare = new Square(7);
            Shape oneRectangle = new Rectangle(3, 4);
            Shape anotherRectangle = new Rectangle(4, 6);
            Shape oneTriangle = new Triangle(9, 2);
            Shape anotherTriangle = new Triangle(3, 10);

            shapes.Add(oneSquare);
            shapes.Add(anotherSquare);
            shapes.Add(oneRectangle);
            shapes.Add(anotherRectangle);
            shapes.Add(oneTriangle);
            shapes.Add(anotherTriangle);

            foreach (var item in shapes)
            {
                var surface = item.CalculateSurface();
                Console.WriteLine("{0} (width {1}, height {2}) => surface: {3}",item.GetType().Name,item.Width, item.Height,surface);
            }
        }