Please help me with the task: Distance is so important

Hello, I’m working on this task:

Measuring distance is an essential task at Wonderland. Create a static class, DistanceMeasurer, that has one public method, GetDistance, with a return type of double, that takes 4 int parameters that represent 2D point coordinates: x1, y1, x2, y2. The GetDistance method should output the distance between the two given points (x and y) on a plane.
In the Main method, read 4 integers from the console, execute GetDistance, and output the result to the screen.
For example:

Here is my code:

namespace Static
   static class DistanceMeasurer
       public static double GetDistance(int px1, int py1, int px2, int py2)
           double distance = 0;
           int x = (px2 - px1) * (px2 - px1);
           int y = (py2 - py1) * (py2 - py1);
           distance = Math.Sqrt(x + y);

           return distance;

   class DistanceIsSoImportant
       public static void Main()
           int x1 = int.Parse(Console.ReadLine());
           int y1 = int.Parse(Console.ReadLine());
           int x2 = int.Parse(Console.ReadLine());
           int y2 = int.Parse(Console.ReadLine());

           DistanceMeasurer.GetDistance(x1, y1, x2, y2);
           Console.WriteLine(DistanceMeasurer.GetDistance(x1, y1, x2, y2));

I’m still weak on the topic “classes”, haven’t found an answer myself, so thanks for help in advance!

your solution is correct!
The only small remark: in the main method you don’t need to call:

DistanceMeasurer.GetDistance(x1, y1, x2, y2);

The validation is failing just because of the naming. To get points for the task you could just remove “p” from all params in your method :
public static double GetDistance(int x1, int y1, int x2, int y2) and inside it.

Thank you much!

1 Like