Advertisement
bokoness

mmn15 Q1

Jun 23rd, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. //TODO: finish documentaion
  2. //TODO: remove
  3. package Mavo2020.Playground;
  4. /**
  5.  * Represent a point
  6.  */
  7. public class Point {
  8.     private double _x;
  9.     private double _y;
  10.  
  11.     /**
  12.      * Constructor
  13.      * @param x the x axis value
  14.      * @param y the y axis value
  15.      */
  16.     public Point(double x, double y) {
  17.         this._x = x;
  18.         this._y = y;
  19.     }
  20.  
  21.     /**
  22.      * Copy constructor
  23.      * @param other the other Point object to copy from
  24.      */
  25.     public Point(Point other) {
  26.         this._x = other._x;
  27.         this._y = other._y;
  28.     }
  29.  
  30.     public double getX() {
  31.         return this._x;
  32.     }
  33.  
  34.     public double getY() {
  35.         return this._y;
  36.     }
  37.  
  38.     public void setX(double x) {
  39.         this._x = x;
  40.     }
  41.  
  42.     public void setY(double y) {
  43.         this._y = y;
  44.     }
  45.  
  46.     public String toString() {
  47.         return "(" + this._x + "," + this._y + ")";
  48.     }
  49.  
  50.     public boolean equals(Point other) {
  51.         return this._x == other._x && this._y == other._y;
  52.     }
  53.  
  54.     public boolean isAbove(Point other) {
  55.         return this._y != other.getY() && this._y > other.getY();
  56.     }
  57.  
  58.     public boolean isUnder(Point other) {
  59.         return !this.isAbove(other);
  60.     }
  61.  
  62.     public boolean isLeft(Point other) {
  63.         return this._x != other.getX() && this._x < other.getX();
  64.     }
  65.  
  66.     public boolean isRight(Point other) {
  67.         return !this.isLeft(other);
  68.     }
  69.  
  70.     public double distance(Point p) {
  71.         return Math.sqrt(Math.pow(this._y - p.getY(), 2) + Math.pow(this._x - p.getX(), 2));
  72.     }
  73.  
  74.     public void move(double dx, double dy) {
  75.         this._x = this._x + dx;
  76.         this._y = this._y + dy;
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement