예제 #1
0
        static void Main(string[] args)
        {
            //composition
            var rectcomp1 = new RectComp(3, 9);

            Console.WriteLine($"The Perimeter of the rectcomp1 is {rectcomp1.Perimeter()}");
            Console.WriteLine($"The Area of the rectcomp1 is {rectcomp1.Area()}");

            Quad fred = new Rectangle();

            Console.WriteLine($"Fred is a {fred.WhatAmI()}");

            var sqr1 = new Square(4);

            Console.WriteLine($"The Perimeter of the Square is {sqr1.Perimeter()}");
            Console.WriteLine($"The Area of the Square is {sqr1.Area()}");
            Console.WriteLine($"The sqr1 is a {sqr1.WhatAmI()}");

            var rect1 = new Rectangle(5, 3);

            Console.WriteLine($"The Perimeter of the Rectangle is {rect1.Perimeter()}");
            Console.WriteLine($"The Area of the Rectangle is {rect1.Area()}");
            Console.WriteLine($"The rect1 is a {rect1.WhatAmI()}");

            var quad1 = new Quad(3, 4, 5, 6);

            {
                //Side1 = 3
                //Side2 = 4
                //Side3 = 5
                //Side4 = 6
            }
            Console.WriteLine($"The Perimeter of the Quadrilateral is {quad1.Perimeter()}");
            Console.WriteLine($"The quad1 is a {quad1.WhatAmI()}");

            var collection = new Quad[]
            {
                fred, sqr1, rect1, quad1
            };

            foreach (var geo in collection)
            {
                Console.WriteLine($"Shape is {geo.WhatAmI()}");
                var hello = geo as Rectangle;
                if (hello != null)
                {
                    Console.WriteLine($"The area of Shape {hello.Area()}");
                }
            }

            var geoshapes = new IGeometricShape[]
            {
                new Circle(1), new Circle(2), new Rectangle(3, 7), new Square(5),
            };

            foreach (var shape in geoshapes)
            {
                Console.WriteLine($"The Perimeter is {shape.Perimeter()} The Area is {shape.Area()}");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            var rectComp = new RectComp(3, 9);

            Console.WriteLine($"The Perimeter of the rectComp is {rectComp.Perimeter()}");
            Console.WriteLine($"The Area of the rectComp is {rectComp.Area()}");

            Rect fred = new Rect(7, 11);

            Console.WriteLine($"Fred is a {fred.WhatAmI()}");

            Sqr sqr1 = new Sqr(4);

            Console.WriteLine($"The Perimeter of the sqr is {sqr1.Perimeter()}");
            Console.WriteLine($"The Area of the sqr is {sqr1.Area()}");
            Console.WriteLine($"The sqr1 is a {sqr1.WhatAmI()}");

            var rect1 = new Rect(5, 3);

            //int p = rect1.Perimeter();
            Console.WriteLine($"The Perimeter of the rect is {rect1.Perimeter()}");
            Console.WriteLine($"The Area of the rect is {rect1.Area()}");
            Console.WriteLine($"The rect1 is a {rect1.WhatAmI()}");

            var quad1 = new Quad(3, 4, 5, 6);

            Console.WriteLine($"The Perimeter of the quad is {quad1.Perimeter()}");
            Console.WriteLine($"The quad1 is a {quad1.WhatAmI()}");

            var collection = new Quad[] {
                fred, sqr1, rect1, quad1
            };

            foreach (var geo in collection)
            {
                Console.WriteLine($"geo is a {geo.WhatAmI()}");
                var rect = geo as Rect;
                if (rect != null)
                {
                    Console.WriteLine($"The area of geo is {rect.Area()}");
                }
            }

            var geoshapes = new IGeometricShape[] {
                new Circle(1), new Circle(2), new Rect(3, 7), new Sqr(5)
            };

            //var geoshapes2 = new IGeometricShape[2];
            //geoshapes2[0] = new Circle(3);
            //geoshapes2[1] = new Circle(4);

            foreach (var shape in geoshapes)
            {
                Console.WriteLine($"Perimeter: {shape.Perimeter()}, Area: {shape.Area()}");
            }
        }