Esempio n. 1
0
        static void Main(string[] args)
        {
            circle    t   = new circle(3.0);
            rectangle re  = new rectangle(3, 4);
            triangle  tri = new triangle(3, 4, 5);

            Console.WriteLine((float)t.Area());
            int   i   = 0;
            float sum = 0;

            while (i < 10)
            {
                Random r = new Random();
                int    n = r.Next(1, 3);
                switch (n)
                {
                case (1):
                    t = new circle((new Random().NextDouble() * 9 + 1));
                    Console.WriteLine((float)t.Area());
                    sum = sum + (float)t.Area();
                    break;

                case (2):
                    re = new rectangle((new Random().NextDouble() * 10 + 1.0), (new Random().NextDouble() * 10) + 1.0);
                    Console.WriteLine((float)re.Area());
                    sum = sum + (float)re.Area();
                    break;

                case (3):
                    double a = 0.0;
                    double b = 0.0;
                    double c = 0.0;
                    while (((a + b) > c) && ((a + c) > b) && ((b + c) > a))
                    {
                        a = new Random().NextDouble() * 10.0 + 1.0;
                        b = new Random().NextDouble() * 10.0 + 1.0;
                        c = new Random().NextDouble() * 10.0 + 1.0;
                    }
                    tri = new triangle((new Random().NextDouble() * 10 + 1), (new Random().NextDouble() * 10 + 1.0), (new Random().NextDouble() * 10 + 1));
                    Console.WriteLine((float)tri.Area());
                    sum = sum + (float)tri.Area();
                    break;

                default:
                    break;
                }
                i++;
            }
            Console.WriteLine(sum);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int count = 0;
               List<ThreeDim> threeList = new List<ThreeDim>();

               List<TwoDim> twoList = new List<TwoDim>();
               int r;
               string shape1;
               while (true)
               {

                   Console.Write("shpae (1.square,2.triangle,3.circle,4.sphere,5.cube) : ");
                   shape1 = Console.ReadLine();
                   if (shape1 != "square" && shape1 != "triangle" && shape1 != "circle" && shape1 != "sphere" && shape1 != "cube")
                   {
                       shape1 = null;
                   }
                   try{
                       process(shape1);
                   }
                   catch(System.ArgumentNullException e)
                   {
                       Console.WriteLine("Enter square or triangle or circle or cube or sphere..please..", e);
                   }
                   try{
                   Console.Write("r : ");
                   r = Int32.Parse(Console.ReadLine());

                    if (shape1 == "square")
                   {
                       foreach (var item in twoList)
                       {
                           if (item.type==1&&item.number==r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           TwoDim square = new Square();
                           Console.WriteLine("Two Dim");
                           Console.WriteLine("길이 : " + square.length(r));
                           Console.WriteLine("넓이 : " + square.Area(r));
                           twoList.Add(square);
                       }
                       count = 0;
                   }
                   else if (shape1 == "triangle")
                   {
                       foreach (var item in twoList)
                       {
                           if (item.type==2&&item.number == r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           TwoDim triangle = new triangle();
                           Console.WriteLine("Two Dim");
                           Console.WriteLine("길이 : " + triangle.length(r));
                           Console.WriteLine("넓이 : " + triangle.Area(r));
                           twoList.Add(triangle);
                       }
                       count = 0;
                   }
                   else if (shape1 == "circle")
                   {
                       foreach (var item in twoList)
                       {
                           if (item.type==3&&item.number == r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           TwoDim circle = new circle();
                           Console.WriteLine("Two Dim");
                           Console.WriteLine("길이 : " + circle.length(r));
                           Console.WriteLine("넓이 : " + circle.Area(r));
                           twoList.Add(circle);
                       }
                       count = 0;
                   }
                   else if (shape1 == "cube")
                   {
                       foreach (var item in threeList)
                       {
                           if (item.type==3&&item.number == r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           ThreeDim cube = new Cube();
                           Console.WriteLine("Three Dim");
                           Console.WriteLine("넓이 : " + cube.Area(r));
                           Console.WriteLine("부피 : " + cube.Volume(r));
                           threeList.Add(cube);
                       }
                       count = 0;
                   }
                   else if (shape1 == "sphere")
                   {
                       foreach (var item in threeList)
                       {
                           if (item.type==4&&item.number == r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           ThreeDim sphere = new Sphere();
                           Console.WriteLine("Three Dim");
                           Console.WriteLine("넓이 : " + sphere.Area(r));
                           Console.WriteLine("부피 : " + sphere.Volume(r));
                           threeList.Add(sphere);
                       }
                       count = 0;
                   }

               }
                   catch (System.FormatException e)
                   {
                       Console.WriteLine("Number..please..", e);

                   }

                   finally {

            }

               }//whlie문
        }
Esempio n. 3
0
        public void run()
        {
            while (true)
            {
                int count1 = twodimlist.Count;
                int count2 = threedimlist.Count;

                Console.WriteLine("\n\nTwoDim Shape : " + count1);
                Console.WriteLine("ThreeDim Shape : " + count2);
                Console.WriteLine("input len and shape");
                int Len = 0;
                try
                {
                    Len = Int32.Parse(Console.ReadLine());
                }
                catch (FormatException ex1)
                {
                    Console.WriteLine(ex1.Message);
                    continue;
                }
                if (Len == 0)
                {
                    break;
                }
                string shape = Console.ReadLine();
                int num = 0;
                foreach (var i in twodimlist)
                {
                    if (i.name == shape && i.len == Len)
                    {
                        Console.WriteLine("이미 존재함");
                        num = 1;
                        break;
                    }
                }
                foreach (var i in threedimlist)
                {
                    if (i.name == shape && i.len == Len)
                    {
                        Console.WriteLine("이미 존재함");
                        num = 1;
                        break;
                    }
                }
                if (num == 1)
                {
                    continue;
                }
                if (shape == "정삼각형")
                {
                    TwoDim Triangle = new triangle();
                    Triangle.name = shape;
                    Triangle.len = Len;
                    Triangle.Calarea();
                    Triangle.Calperimeter();
                    Triangle.print(Triangle.Area, Triangle.perimeter);
                    twodimlist.Add(Triangle);
                }
                else if (shape == "정사각형")
                {
                    TwoDim Square = new square();
                    Square.name = shape;
                    Square.len = Len;
                    Square.Calarea();
                    Square.Calperimeter();
                    Square.print(Square.Area, Square.perimeter);
                    twodimlist.Add(Square);
                }
                else if (shape == "원")
                {
                    TwoDim Circle = new circle();
                    Circle.name = shape;
                    Circle.len = Len;
                    Circle.Calarea();
                    Circle.Calperimeter();
                    Circle.print(Circle.Area, Circle.perimeter);
                    twodimlist.Add(Circle);
                }
                else if (shape == "구")
                {
                    ThreeDim Sphere = new sphere();
                    Sphere.name = shape;
                    Sphere.len = Len;
                    Sphere.Calarea();
                    Sphere.Calvolume();
                    Sphere.print(Sphere.Area, Sphere.volume);
                    threedimlist.Add(Sphere);
                }
                else if (shape == "정육면체")
                {
                    ThreeDim Cube = new cube();
                    Cube.name = shape;
                    Cube.len = Len;
                    Cube.Calarea();
                    Cube.Calvolume();
                    Cube.print(Cube.Area, Cube.volume);
                    threedimlist.Add(Cube);
                }
                else
                {
                    Console.WriteLine("Wrong input");
                }
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            int count = 0;
               List<ThreeDim> threeList = new List<ThreeDim>();

               List<TwoDim> twoList = new List<TwoDim>();
               int r;
               string shape1;
               while (true)
               {
                   Console.Write("shpae (1.square,2.triangle,3.circle,4.sphere,5.cube) : ");
                   shape1 = Console.ReadLine();
                   Console.Write("r : ");
                   r = Int32.Parse(Console.ReadLine());
                   if (shape1 == "square")
                   {
                       foreach (var item in twoList)
                       {
                           if (item.type==1&&item.number==r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           TwoDim square = new Square();
                           Console.WriteLine("Two Dim");
                           Console.WriteLine("길이 : " + square.length(r));
                           Console.WriteLine("넓이 : " + square.Area(r));
                           twoList.Add(square);
                       }
                       count = 0;
                   }
                   else if (shape1 == "triangle")
                   {
                       foreach (var item in twoList)
                       {
                           if (item.type==2&&item.number == r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           TwoDim triangle = new triangle();
                           Console.WriteLine("Two Dim");
                           Console.WriteLine("길이 : " + triangle.length(r));
                           Console.WriteLine("넓이 : " + triangle.Area(r));
                           twoList.Add(triangle);
                       }
                       count = 0;
                   }
                   else if (shape1 == "circle")
                   {
                       foreach (var item in twoList)
                       {
                           if (item.type==3&&item.number == r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           TwoDim circle = new circle();
                           Console.WriteLine("Two Dim");
                           Console.WriteLine("길이 : " + circle.length(r));
                           Console.WriteLine("넓이 : " + circle.Area(r));
                           twoList.Add(circle);
                       }
                       count = 0;
                   }
                   else if (shape1 == "cube")
                   {
                       foreach (var item in threeList)
                       {
                           if (item.type==3&&item.number == r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           ThreeDim cube = new Cube();
                           Console.WriteLine("Three Dim");
                           Console.WriteLine("넓이 : " + cube.Area(r));
                           Console.WriteLine("부피 : " + cube.Volume(r));
                           threeList.Add(cube);
                       }
                       count = 0;
                   }
                   else if (shape1 == "sphere")
                   {
                       foreach (var item in threeList)
                       {
                           if (item.type==4&&item.number == r)
                           {
                               Console.WriteLine("이미 존재 합니다..");
                               count = 1;
                               break;
                           }

                       }
                       if (count == 0)
                       {
                           ThreeDim sphere = new Sphere();
                           Console.WriteLine("Three Dim");
                           Console.WriteLine("넓이 : " + sphere.Area(r));
                           Console.WriteLine("부피 : " + sphere.Volume(r));
                           threeList.Add(sphere);
                       }
                       count = 0;
                   }

               }
        }
Esempio n. 5
0
        public void run()
        {
            while (true)
            {
                int count1 = twodimlist.Count;
                int count2 = threedimlist.Count;

                Console.WriteLine("\n\nTwoDim Shape : " + count1);
                Console.WriteLine("ThreeDim Shape : " + count2);
                Console.WriteLine("input len and shape");
                int Len = 0;
                try
                {
                    Len = Int32.Parse(Console.ReadLine());
                }
                catch (FormatException ex1)
                {
                    Console.WriteLine(ex1.Message);
                    continue;
                }
                if (Len == 0)
                {
                    break;
                }
                string shape = Console.ReadLine();
                int    num   = 0;
                foreach (var i in twodimlist)
                {
                    if (i.name == shape && i.len == Len)
                    {
                        Console.WriteLine("이미 존재함");
                        num = 1;
                        break;
                    }
                }
                foreach (var i in threedimlist)
                {
                    if (i.name == shape && i.len == Len)
                    {
                        Console.WriteLine("이미 존재함");
                        num = 1;
                        break;
                    }
                }
                if (num == 1)
                {
                    continue;
                }
                if (shape == "정삼각형")
                {
                    TwoDim Triangle = new triangle();
                    Triangle.name = shape;
                    Triangle.len  = Len;
                    Triangle.Calarea();
                    Triangle.Calperimeter();
                    Triangle.print(Triangle.Area, Triangle.perimeter);
                    twodimlist.Add(Triangle);
                }
                else if (shape == "정사각형")
                {
                    TwoDim Square = new square();
                    Square.name = shape;
                    Square.len  = Len;
                    Square.Calarea();
                    Square.Calperimeter();
                    Square.print(Square.Area, Square.perimeter);
                    twodimlist.Add(Square);
                }
                else if (shape == "원")
                {
                    TwoDim Circle = new circle();
                    Circle.name = shape;
                    Circle.len  = Len;
                    Circle.Calarea();
                    Circle.Calperimeter();
                    Circle.print(Circle.Area, Circle.perimeter);
                    twodimlist.Add(Circle);
                }
                else if (shape == "구")
                {
                    ThreeDim Sphere = new sphere();
                    Sphere.name = shape;
                    Sphere.len  = Len;
                    Sphere.Calarea();
                    Sphere.Calvolume();
                    Sphere.print(Sphere.Area, Sphere.volume);
                    threedimlist.Add(Sphere);
                }
                else if (shape == "정육면체")
                {
                    ThreeDim Cube = new cube();
                    Cube.name = shape;
                    Cube.len  = Len;
                    Cube.Calarea();
                    Cube.Calvolume();
                    Cube.print(Cube.Area, Cube.volume);
                    threedimlist.Add(Cube);
                }
                else
                {
                    Console.WriteLine("Wrong input");
                }
            }
        }