// Exercise 4b from Lecture 4: points with properties using System; class PointPublic { public int x; public int y; public PointPublic(int x, int y){ this.x = x; this.y = y; } } class PointMethods { private int x; private int y; public PointMethods(int x, int y){ this.x = x; this.y = y; } public int GetX() {return(x);} public int GetY() {return(y);} } class PointProperties { private int x; private int y; public int PointX { get { return x; } set { this.x = value; } } public int PointY { get { return y; } set { this.y = value; } } public PointProperties(int x, int y){ this.x = x; this.y = y; } } class Tester { public static void Main(){ PointPublic point1 = new PointPublic(5,10); PointPublic point2 = new PointPublic(20, 15); Console.WriteLine("Point1({0}, {1})", point1.x, point1.y); Console.WriteLine("Point2({0}, {1})", point2.x, point2.y); PointMethods point3 = new PointMethods(5,10); PointMethods point4 = new PointMethods(20, 15); Console.WriteLine("Point1({0}, {1})", point3.GetX(), point3.GetY()); Console.WriteLine("Point2({0}, {1})", point4.GetX(), point4.GetY()); // Console.WriteLine("Point1 (as property): ", PointX); // Console.WriteLine("Point2 (as property): ", PointY); PointProperties point5 = new PointProperties(5,10); PointProperties point6 = new PointProperties(20, 15); Console.WriteLine("Point1({0}, {1})", point5.PointX, point5.PointY); Console.WriteLine("Point2({0}, {1})", point6.PointX, point6.PointY); point5.PointX += 10; Console.WriteLine("Increasing Point1's x val by 10 ..."); Console.WriteLine("Point1({0}, {1})", point5.PointX, point5.PointY); } }