Idoor

Point3D

Sep 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. package classes;
  2.  
  3. public class Point3D {
  4.     public double x, y, z;
  5.  
  6.     public Point3D(double x, double y, double z){
  7.         this.x = x;
  8.         this.y = y;
  9.         this.z = z;
  10.     }
  11.  
  12.     public Point3D(){
  13.         this.x = 0;
  14.         this.y = 0;
  15.         this.z = 0;
  16.     }
  17.  
  18.     public double getX() {
  19.         return x;
  20.     }
  21.  
  22.     public double getY() {
  23.         return y;
  24.     }
  25.  
  26.     public double getZ() {
  27.         return z;
  28.     }
  29.  
  30.     public void setX(double x) {
  31.         this.x = x;
  32.     }
  33.  
  34.     public void setY(double y) {
  35.         this.y = y;
  36.     }
  37.  
  38.     public void setZ(double z) {
  39.         this.z = z;
  40.     }
  41.  
  42.     public void Out(){
  43.         System.out.println("Координаты точки: x = " +x);
  44.         System.out.println("Координаты точки: y = " +y);
  45.         System.out.println("Координаты точки: z = " +z);
  46.     }
  47.  
  48.     @Override
  49.     public boolean equals(Object o) {
  50.         if (this == o) return true;
  51.         if (o == null || getClass() != o.getClass()) return false;
  52.  
  53.         Point3D point3D = (Point3D) o;
  54.  
  55.         if (Double.compare(point3D.x, x) != 0) return false;
  56.         if (Double.compare(point3D.y, y) != 0) return false;
  57.         return Double.compare(point3D.z, z) == 0;
  58.     }
  59.  
  60.     public static void main(String args[]){
  61.         Point3D point_first = new Point3D(1, 2, 3);
  62.         Point3D point_second = new Point3D();
  63.         if(point_first == point_second) {System.out.println("Точки равны");}
  64.         else {System.out.println("Точки не равны");}
  65.  
  66.         if(point_first == point_first) {System.out.println("Точка равна себе");}
  67.         else {System.out.println("Точка не равна себе");}
  68.  
  69.         Point3D point_third = new Point3D(1, 2, 3);
  70.         if(point_first.equals(point_third)) {System.out.println("Точки равны");}
  71.         else {System.out.println("Точки не равны");}
  72.  
  73.         point_second.Out();
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment