| csharp-3/extension-methods/Client.cs - A Client of class Point which uses an extension method DistanceTo. | Lecture 5 - slide 28 : 29 Program 2 |
// A client of Point that instantiates three points and calculates
// the circumference of the implied triangle.
using System;
public class Application{
public static void Main(){
Point p1 = PromptPoint("Enter first point"),
p2 = PromptPoint("Enter second point"),
p3 = PromptPoint("Enter third point");
double p1p2Dist = p1.DistanceTo(p2),
p2p3Dist = p2.DistanceTo(p3),
p3p1Dist = p3.DistanceTo(p1);
double circumference = p1p2Dist + p2p3Dist + p3p1Dist;
Console.WriteLine("Circumference: {0} {1} {2}: {3}",
p1, p2, p3, circumference);
}
public static Point PromptPoint(string prompt){
Console.WriteLine(prompt);
double x = double.Parse(Console.ReadLine()),
y = double.Parse(Console.ReadLine());
return new Point(x,y, Point.PointRepresentation.Rectangular);
}
}