Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- class Point
- {
- private int[] _point = new int[3];
- public Point(int x, int y, int z)
- {
- X = x;
- Y = y;
- Z = z;
- }
- public double _mass;
- public int X
- {
- get => _point[0];
- set => _point[0] = value;
- }
- public int Y
- {
- get => _point[1];
- set => _point[1] = value;
- }
- public int Z
- {
- get => _point[2];
- set => _point[2] = value;
- }
- public double Mass
- {
- get => _mass;
- set => _mass = value > 0 ? value : 0;
- }
- public bool IsZero()
- {
- if (X == 0 && Y == 0 && Z == 0) return true;
- else return false;
- }
- public double Distance(Point p)
- {
- double _distance = Math.Sqrt((p.X - X) * (p.X - X) + (p.Y - Y) * (p.Y - Y) + (p.Z - Z)* (p.Z - Z));
- return _distance;
- }
- }
- static void Main()
- {
- Point p1 = new Point(0, 0, 0);
- Point p2 = new Point(1, 2, 3);
- p1.Mass = 0.33;
- p2.Mass = -0.33;
- Console.WriteLine("All p1 coordinates are 0? " + p1.IsZero());
- Console.WriteLine("Weight of p2 is " + p2.Mass + ", but at first it was -0.33");
- Console.WriteLine("Distance between p1 and p2 is " + p1.Distance(p2));
- p1.X = 3;
- p1.Y = 4;
- p1.Z = 1;
- Console.WriteLine($"After changing, the coordinates of point p1 is ({p1.X};{p1.Y};{p1.Z})");
- Console.ReadKey();
- }
- }
Add Comment
Please, Sign In to add comment