public static Product GetShape(string shape)

        {
            Product iproduct = null;

            if (shape.Equals("triangle"))
            {
                iproduct = new triangle();
            }
            else if (shape.Equals("circle"))
            {
                iproduct = new circle();
            }
            else if (shape.Equals("square"))
            {
                iproduct = new square();
            }
            else if (shape.Equals("rectangle"))
            {
                iproduct = new rectangle();
            }
            else
            {
                Console.WriteLine("不支持此图形!!");
            }

            return(iproduct);
        }
Exemplo n.º 2
0
        public static Graph createGraph(string type)
        {
            Graph shape = null;

            switch (type)
            {
            case "圆":
                Console.WriteLine("请输入半径:");
                string s = Console.ReadLine();
                double R = Double.Parse(s);
                shape = new circle {
                    r = R
                };
                break;

            case "三角形":
                Console.WriteLine("请输入三边(整形):");
                s = Console.ReadLine();
                int a = int.Parse(s);
                s = Console.ReadLine();
                int b = int.Parse(s);
                s = Console.ReadLine();
                int c = int.Parse(s);
                shape = new triangle {
                    a = a, b = b, c = c
                };
                break;

            case "正方形":
                Console.WriteLine("请输入边长:");
                s = Console.ReadLine();
                double L = double.Parse(s);
                shape = new square {
                    L = L
                };
                break;

            case "长方形":
                Console.WriteLine("请输入两边长:");
                s = Console.ReadLine();
                L = double.Parse(s);
                s = Console.ReadLine();
                double K = double.Parse(s);
                shape = new rectangle {
                    L = L, K = K
                };
                break;
            }
            return(shape);
        }