public class PointI {

// DATA Fields (variables)

   private int x;
   private int y;

// Constructors (made with "new")

   public PointI () {
      this(0, 0);
   }

   public PointI (int x, int y) {
      this.x = x;
      this.y = y;
   }
   
   
   // Construct using Polar coordinates
   public PointI (double r, int theta){
      double xR = toCartesianX(r, theta);
      double yR = toCartesianY(r, theta);
      x = (int) Math.round(xR);
      y = (int) Math.round(yR);
   }
   

// BEHAVIOR Methods

   public void setX(int x){
      this.x = x;
   }   
   
   public void setY(int y){
      this.y = y;
   }
   
   public int getX(){
      return x;
   }   
   
   public int getY(){
      return y;
   }
   
   public String toString(){
      return "PointI: x = " + x + " y = " + y;
   }
   
   // Distance between this point and another point: sqrt(dx*dx + dy*dy)
   public double length(PointI p){
      return Math.sqrt( (p.getX() - x)*(p.getX() - x) + 
         (p.getY() - y)*(p.getY() - y) );
   }
   
   /** Rotate an angle alpha about the origin */
   public void rotate(int alpha) {
   
      double a = (double) alpha * Math.PI/180.;
      double xR = (double) this.x;
      double yR = (double) this.y;
      double xPrime = xR * Math.cos(a) - yR * Math.sin(a);
      double yPrime = xR * Math.sin(a) + yR * Math.cos(a);
      this.x = (int) Math.round ( xPrime);
      this.y = (int) Math.round ( yPrime);
   
   }
   
   public void rotate(int alpha, PointI axis){
      translate(axis.opposite());
      rotate(alpha);
      translate(axis);
   }

   public void translate(int dx, int dy){
      this.x += dx;
      this.y += dy;
   }   
   
   
   public void translate(PointI p){
      translate(p.getX(), p.getY());
   }
   
   public PointI opposite() {
      return new PointI(-this.x, -this.y);
   }
   
   // Cartesian (x, y) and Polar coordinates (r, theta)

   public static double toCartesianX(double r, int theta){
      return r*Math.cos(theta*Math.PI/180.);
   }
   
   public static double toCartesianY(double r, int theta){
      return r*Math.sin(theta*Math.PI/180.);
   }
   
   public double toPolarR(){
      return length(new PointI());
   }   
   
   public int toPolarTheta(){
      double thetaR = Math.atan((double) y/(double) x)*180./Math.PI;
      return (int) Math.round(thetaR);
   }

   
}