Advertisement
dimipan80

User Defined Class Point

Aug 17th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. // Define class Point, to using in some of next tasks.
  2.  
  3. public class Point {
  4.     private double x, y;
  5.  
  6.     public double getX() {
  7.         return x;
  8.     }
  9.  
  10.     public void setX(double x) {
  11.         this.x = x;
  12.     }
  13.  
  14.     public double getY() {
  15.         return y;
  16.     }
  17.  
  18.     public void setY(double y) {
  19.         this.y = y;
  20.     }
  21.  
  22.     public Point(double x, double y) {
  23.         // TODO Auto-generated constructor stub
  24.         this.x = x;
  25.         this.y = y;
  26.     }
  27.  
  28.     public static double minusX(Point point1, Point point2) {
  29.         return point1.x - point2.x;
  30.     }
  31.  
  32.     public static double minusY(Point point1, Point point2) {
  33.         return point1.y - point2.y;
  34.     }
  35.  
  36.     public static double distanceBetween(Point point1, Point point2) {
  37.         double deltaX = Point.minusX(point2, point1);
  38.         double deltaY = Point.minusY(point2, point1);
  39.  
  40.         return Math.sqrt((deltaX * deltaX) + (deltaY * deltaY));
  41.     }
  42.  
  43.     public static boolean equals(Point point1, Point point2) {
  44.         return point1.x == point2.x && point1.y == point2.y;
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement