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:
>2
>1
>3
>4
3.16227766016838
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!