Esempio n. 1
0
        static void Main(string[] args)
        {
            List<TwoDim> twodim = new List<TwoDim>();
            List<ThreeDim> threedim = new List<ThreeDim>();
            while (true)
            {
                Console.WriteLine("도형종류 : Triangle, Square, Circle, Cube, Sphere");
                double number;
                Console.Write("단위 크기 : ");
                try
                {
                    number = Double.Parse(Console.ReadLine());
                    if (number<=0)
                    {
                        Console.WriteLine("잘못된 범위의 값을 입력하였습니다.");
                        continue;
                    }
                }
                catch (System.FormatException x)
                {
                    Console.WriteLine(x.Message);
                    continue;
                }
                catch (SystemException y)
                {
                    Console.WriteLine(y.Message);
                    continue;
                }

                Console.Write("모양 : ");

                string whatShape = Console.ReadLine();
                int count = 0;
                int i = 0;
                if (whatShape != "Triangle" && whatShape != "Square" && whatShape != "Circle"&&whatShape!="Cube"&&whatShape!="Sphere")
                {
                    Console.WriteLine("없는 도형입니다.");
                    continue;
                }
                else if (whatShape == "Triangle")
                {
                    TwoDim tri = new Triangle();
                    foreach (var item in twodim)
                    {
                        if (twodim[i].typeTwo == 3 && twodim[i].numTwo == number)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        tri.typeTwo = 3;
                        tri.numTwo = number;
                        tri.Length(number);
                        tri.Area(number);
                        twodim.Add(tri);
                        i = 0;
                    }
                    count = 0;
                }
                else if (whatShape == "Square")
                {
                    TwoDim squ = new Square();
                    foreach (var item in twodim)
                    {
                        if (twodim[i].typeTwo == 4 && twodim[i].numTwo == number)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        squ.typeTwo = 4;
                        squ.numTwo = number;
                        squ.Length(number);
                        squ.Area(number);
                        twodim.Add(squ);
                        i = 0;
                    }
                    count = 0;
                }
                else if (whatShape == "Circle")
                {
                    TwoDim cir = new Circle();
                    foreach (var item in twodim)
                    {
                        if (twodim[i].typeTwo == 0 && twodim[i].numTwo == number)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        cir.typeTwo = 0;
                        cir.numTwo = number;
                        cir.Length(number);
                        cir.Area(number);
                        twodim.Add(cir);
                        i = 0;
                    }
                    count = 0;
                }
                else if (whatShape == "Cube")
                {
                    ThreeDim cub = new Cube();
                    foreach (var item in threedim)
                    {
                        if (threedim[i].numThree == number && threedim[i].typeThree == 6)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        cub.typeThree = 6;
                        cub.Area(number);
                        cub.Volume(number);
                        threedim.Add(cub);
                        i = 0;
                    }
                    count = 0;
                }
                else if (whatShape == "Sphere")
                {
                    ThreeDim sph = new Sphere();
                    foreach (var item in threedim)
                    {
                        if (threedim[i].numThree == number && threedim[i].typeThree == 6)
                        {
                            Console.WriteLine("이미 담은 도형입니다.");
                            count += 1;
                            break;
                        }
                        i++;
                    }
                    if (count == 0)
                    {
                        sph.typeThree = 0;
                        sph.Area(number);
                        sph.Volume(number);
                        threedim.Add(sph);
                        i = 0;
                    }
                    count = 0;
                }
            }
        }