import java.util.Scanner;
public class Vector
{
  double x=0;
  double y=0;
  
  public static void main(String args[])
  {
    Scanner teclado=new Scanner(System.in);
    System.out.println("Operaciones con vectores en el plano");
    Vector anterior=new Vector();
    for(int num=1; true; num++)
    {
      
      System.out.println("\n\nVector " + num + ": ");
      Vector v1=new Vector();
      System.out.print("x: ");
      v1.x=teclado.nextDouble();
      System.out.print("\ny: ");
      v1.y=teclado.nextDouble();
      if(v1.x==0 && v1.y==0)
        break;
      
      System.out.print("V" + num + ": ");
      v1.imprimirVector(v1.x,v1.y);
      if (num!=1)
      {
        System.out.print("\n\nV" + (num-1) + " + V" + num + " : ");
        v1.sumarVector(v1.x, v1.y, anterior);
        
        System.out.print("\nV" + (num-1) + " - V" + num + " : ");
        v1.restar12(v1.x, v1.y, anterior);
        
        System.out.print("\nV" + num + " - V" + (num-1)+ " : ");
        v1.restar21(v1.x, v1.y, anterior);
      }
      anterior=v1;
    }
  }
  
  public void imprimirVector(double x, double y)
  {
    System.out.print("(x, y)= (" + x + ", " + y + "); (r, 0) = (");
    System.out.printf("%4.2f, %4.2f)", Math.sqrt(x*x + y*y),Math.atan2(y,x));
  }
  
  public void sumarVector(double x, double y, Vector anterior)
  {
    double X=x+anterior.x;
    double Y=y+anterior.y;
    imprimirVector(X,Y);
  }
  
  public void restar12 (double x, double y, Vector anterior)
  {
    double X=anterior.x-x;
    double Y=anterior.y-y;
    imprimirVector(X,Y);
  }
  
  public void restar21(double x, double y, Vector anterior)
  {
    double X=x-anterior.x;
    double Y=y-anterior.y;
    imprimirVector(X,Y);
  }
}