Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("欢迎来到图形工厂,请输入你想要创建的图形:\r\nTriangle代表三角形,Circle代表圆形,\r\nSquare代表正方形,Rectangle代表长方形\r\n输入0可以退出程序");
            String graphName = null;

            graphName = Console.ReadLine();
            GraphFactory factory = new GraphFactory();
            Graph        graph   = null;

            while (String.Compare(graphName, "0") != 0)
            {
                if (String.Compare(graphName, "Triangle") == 0 || String.Compare(graphName, "Circle") == 0 || String.Compare(graphName, "Rectangle") == 0 || String.Compare(graphName, "Square") == 0)
                {
                    graph = factory.createGraph(graphName);
                    double a = graph.getArea();
                    Console.WriteLine("面积为: " + graph.getArea());
                    Console.WriteLine("\r\n请输入你想要创建的图形:(Triangle,Circle,Square,Rectangle,0退出)");
                    graphName = Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("输入无效字符,请重新输入有效字符:(Triangle,Circle,Square,Rectangle,0退出)");
                    graphName = Console.ReadLine();
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("请输入图形的名称(正方形、三角形、圆形、长方形):");

            Graph graph = GraphFactory.GetGraph(Console.ReadLine());

            graph.Display();
        }