Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Which type of shape do you want to create :(rectangle,square,triangle,circle)");
            string shapeType = Convert.ToString(Console.ReadLine());
            Shape  shape     = ShapeFactory.GetShape(shapeType);

            Console.WriteLine("The area of the " + shapeType + " is " + shape.getArea());
        }
Esempio n. 2
0
        static void Main()
        {
            Shape shape;

            //圆形
            Console.WriteLine("创建半径为5的圆形");
            shape = ShapeFactory.GetShape("circle", 5);
            shape.ShowArea();
            //矩形
            Console.WriteLine("创建边长为2, 4的矩形");
            shape = ShapeFactory.GetShape("rect", 2, 4);
            shape.ShowArea();
            //三角形
            Console.WriteLine("创建底3, 高4的三角形");
            shape = ShapeFactory.GetShape("triangle", 3, 4);
            shape.ShowArea();
            //正方形
            Console.WriteLine("创建边长为1的正方形");
            shape = ShapeFactory.GetShape("square", 1);
            shape.ShowArea();
            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Shape shape_1;

            shape_1 = ShapeFactory.GetShape("TRIANGLE");
            shape_1.Draw();
            Console.WriteLine("The area is : " + shape_1.Area);
            Shape shape_2;

            shape_2 = ShapeFactory.GetShape("CIRCLE");
            shape_2.Draw();
            Console.WriteLine("The area is : " + shape_2.Area);
            Shape shape_3;

            shape_3 = ShapeFactory.GetShape("SQUARE");
            shape_3.Draw();
            Console.WriteLine("The area is : " + shape_3.Area);
            Shape shape_4;

            shape_4 = ShapeFactory.GetShape("RECTANGLE");
            shape_4.Draw();
            Console.WriteLine("The area is : " + shape_4.Area);
        }