示例#1
0
        static void Main(string[] args)
        {
            Circle circle1 = new Circle(1, 1, 4);
            Circle circle2 = new Circle(8, 5, 7);
            Point  point1  = new Point(1, 5);
            Point  point2  = new Point(4, 3);

            //starting info
            Console.WriteLine(circle1.ToString());
            Console.WriteLine(circle2.ToString());
            Console.WriteLine(point1.ToString());
            Console.WriteLine(point2.ToString());

            //moves everything
            Console.WriteLine("\nMoving points and circles...\n\n");
            circle1.MoveTo(2, 2);
            circle2.MoveBy(-4, -2);
            point1.MoveTo(1, 1);
            point2.MoveBy(-4, -3);

            //next info pannel
            Console.WriteLine(circle1.ToString());
            Console.WriteLine(circle2.ToString());
            Console.WriteLine(point1.ToString());
            Console.WriteLine(point2.ToString());

            Console.WriteLine("The distance between the points is " + point1.DistanceTo(point2));
            Console.WriteLine("The distance between the first point and the second circle is " + point1.DistanceTo(circle2));

            if (circle1.IsLargerThan(circle2))
            {
                Console.WriteLine("\nThe first circle is larger than the second one");
            }
            else
            {
                Console.WriteLine("\nThe second circle is larger than the first one");
            }

            if (circle1.ContainsPosition(point1))
            {
                Console.WriteLine("Circle one contains point one");
            }
            if (circle2.ContainsPosition(point1))
            {
                Console.WriteLine("Circle two contains point one");
            }
            if (circle1.ContainsPosition(point2))
            {
                Console.WriteLine("Circle one contains point two");
            }
            if (circle2.ContainsPosition(point2))
            {
                Console.WriteLine("Circle two contains point two");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            // Initialize objects
            Point  p1 = new Point(5, 7);
            Point  p2 = new Point(10, 10);
            Circle c1 = new Circle(10, 10, 3);
            Circle c2 = new Circle(0, 0, 5);

            // Output initial objects
            Console.WriteLine(p1);
            Console.WriteLine(p2);
            Console.WriteLine(c1);
            Console.WriteLine(c2);

            // Move two objects
            Console.WriteLine("\nMoving point 2 to (2, 2)");
            Console.WriteLine("Moving circle 2 by (-1, -1)\n");
            p2.MoveTo(2, 2);
            c2.MoveBy(-1, -1);

            // Output moved objects
            Console.WriteLine(p1);
            Console.WriteLine(p2);
            Console.WriteLine(c1);
            Console.WriteLine(c2);

            // Output distances
            Console.WriteLine($"\nDistance between point 1 and point 2: {p1.DistanceTo(p2)}");
            Console.WriteLine($"Distance between point 1 and circle 1: {p1.DistanceTo(c1)}");
            Console.WriteLine($"Distance between point 1 and circle 2: {p1.DistanceTo(c2)}");
            Console.WriteLine($"Distance between point 2 and circle 1: {p2.DistanceTo(c1)}");
            Console.WriteLine($"Distance between point 2 and circle 2: {p2.DistanceTo(c2)}\n");

            // Compare circle areas
            if (c1.IsLargerThan(c2))
            {
                Console.WriteLine($"Circle 1's area ({c1.Area}) is larger than circle 2's area ({c2.Area})\n");
            }
            else if (c2.IsLargerThan(c1))
            {
                Console.WriteLine($"Circle 2's area ({c2.Area}) is larger than circle 1's area ({c1.Area})\n");
            }
            else
            {
                Console.WriteLine($"Circle 1's area ({c1.Area}) is equal to circle 2's area ({c2.Area})\n");
            }

            // Check is circles contain points
            Console.Write("Does circle 1 contain point 1?: ");
            if (c1.ContainsPosition(p1))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.Write("Does circle 1 contain point 2?: ");
            if (c1.ContainsPosition(p2))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.Write("Does circle 2 contain point 1?: ");
            if (c2.ContainsPosition(p1))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.Write("Does circle 2 contain point 2?: ");
            if (c2.ContainsPosition(p2))
            {
                Console.WriteLine("Yes\n");
            }
            else
            {
                Console.WriteLine("No\n");
            }

            // Keep the window open!
            Console.WriteLine("Press any key to continue. . .");
            Console.ReadKey();
        }