// Allison Obourn
// CS& 141, Winter 2021
// Lecture 15

// Blueprint for creating objects of type Point
// which represents a location on a 2D x, y plane


import java.awt.*;

public class Point {
   private int x;
   private int y;
   
   // Creates a Point with the provided x and y
   // coordinates
   public Point(int startX, int startY) {
      x = startX;
      y = startY;
   }
   
   // Creates a Point with x and y coordinates
   // set to the origin
   public Point() {
      x = 0;
      y = 0;
   }
   
   // sets the x coordinate to the passed in value
   public void setX(int newX) {
      x = newX;
   }
   
   // sets the y coordinate to the passed in value
   public void setY(int newY) {
      y = newY;
   }
   
   // returns the x coordinate
   public int getX() {
      return x;
   }
   
   // returns the y coordinate
   public int getY() {
      return y;
   }
   
   // Draws a point as a dot with a coordinate label
   // with the provided Graphics g
   public void draw(Graphics g) {
      g.fillOval(x, y, 3, 3);
      String label = toString();
      g.drawString(label, x, y);
      
   }
   
   // Moves the Point's x and y by a provided dx and
   // dy amount
   public void translate(int dx, int dy) {
      x += dx;
      y += dy;
   }
   
   // returns a String in the format of (23, 42)
   // where the numbers are the x and y coordinates
   public String toString() {
      return "(" + x + ", " + y + ")";
   }
   
   // returns the distance between this point and the passed in point
   // using the formuls squareroot ((x1-x2)^2 + (y1-y2)^2)
   public double distance(Point other) {
      int dx = x - other.x;
      int dy = y - other.y;
      return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
   }
}