Objects and Classes - Lab Closest Two Points
Здравейте, имам едно въпросче относно задача 05 Objects and Classes-Lab.Не мога да разбера защо ми се чупи кога при отделните класове,които съм задал.Ако някой може да намери по опростен вариант моля за помощ.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Point
{
public double X { get; set; }
public double Y { get; set; }
public string Name { get; set; }
public bool IsOnTheLeftFrom(Point p2)
{
var onTheLeft = this.X < p2.X;
return onTheLeft;
}
public override string ToString()
{
return String.Format("{0}{1}, {2}",this.Name,this.X,this.Y);
}
public Point ReadPoint()
{
var coords = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
var p = new Point() { X = coords[0], Y = coords[1] };
return p;
}
public double CalcDistance(Point p1, Point p2)
{
var a = p1.X - p2.X;
var b = p1.Y - p2.Y;
return Math.Sqrt(a * a + b * b);
}
public static Point[] ReadarrayOfPoints()
{
int n = int.Parse(Console.ReadLine());
var points = new Point[n];
for (int i = 0; i < n; i++)
{
points[i] = Point.ReadPoint[n];
}
}
}
class Program
{
static void Main()
{
var points =Point. ReadarrayOfPoints();
var nearestPoints = FindNearestPoints(points);
Console.WriteLine(Point.CalcDistance(nearestPoints[0],nearestPoints[1]));
Console.WriteLine(nearestPoints[0]);
Console.WriteLine(nearestPoints[1]);
}
static Point[] FindNearestPoints(Point[] points)
{
var minDistance = double.MaxValue;
Point[] nearestPoints = null;
;
for (int first = 0; first < points.Length; first++)
{
for (int second = first+1; second < points.Length; second++)
{
var p1 = points[first];
var p2 = points[second];
var dist = Point.Caldistance(p1, p2);
if (dist<minDistance)
{
minDistance = dist;
nearestPoints = new Point[] { p1, p2 };
}
}
}
return nearestPoints;
}
}
.