Advertisement
mmayoub

Point, 03.07.2021

Jul 10th, 2021
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1.  
  2. public class Point {
  3.     static private int count=0;
  4.     private double x;
  5.     private double y;
  6.    
  7.     public Point(double x, double y) {
  8.         this.x=x;
  9.         this.y=y;
  10.        
  11.         count++;
  12.         System.out.println("Total created Points is " + count);
  13.     }
  14.  
  15.     public double getX() {
  16.         return x;
  17.     }
  18.  
  19.     public void setX(double x) {
  20.         this.x = x;
  21.     }
  22.  
  23.     public double getY() {
  24.         return y;
  25.     }
  26.  
  27.     public void setY(double y) {
  28.         this.y = y;
  29.     }
  30.  
  31.     public double distance(Point p) {
  32.         // return Math.sqrt(Math.pow(this.x-p.x, 2) + Math.pow(this.y-p.y, 2));
  33.        
  34.         double dx = this.x -p.x;
  35.         double dy = this.y-p.y;
  36.        
  37.         dx = Math.pow(dx, 2);
  38.         dy = Math.pow(dy,2);
  39.        
  40.         return Math.sqrt(dx+dy);
  41.          
  42.     }
  43.    
  44.     public Point middle(Point p) {
  45.         double xmid = (this.x+p.x) / 2;
  46.         double ymid =(this.y+p.y)/2;
  47.        
  48.         Point mid = new Point(xmid, ymid);
  49.         return mid;
  50.     }
  51.    
  52.     @Override
  53.     public String toString() {
  54.         return "(" + this.x + ", " + this.y + ")";
  55.     }
  56.    
  57.      public static  int getCount() {
  58.         return count;
  59.     }
  60.  
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement