import java.util.Scanner;
public class Vector
{
  Scanner teclado = new Scanner(System.in);
  
  private double x = 0;
  private double y = 0;  
  static int i = 1;
  
  public static void main(String args[])
  {
    System.out.printf("Operaciones con vectores en el plano%n%n");
    
    Vector vector1 = null;
    Vector vector2 = new Vector();
    Vector resultado = null;
    
    for (i = 1; ; ++i)
    {
      vector2.ingresarVector();
      if ( ! vector2.esVector() )
        return;
      vector2.imprimirVector();
      if ( vector1 != null)
      {
        resultado = vector2.sumaVectores(vector1);
        resultado.imprimirSumaVectores();
        resultado = vector2.restaVectores1(vector1);
        resultado.imprimirrestaVectores1();
        resultado = vector2.restaVectores2(vector1);
        resultado.imprimirrestaVectores2();
      }
      vector1 = vector2;
      vector2 = new Vector();
    }
  }
  
  public Vector()
  {
    x = 0;
    y = 0;
  }  
  
  public void ingresarVector()
  {
    System.out.printf("Vector %d:", i);
    x = teclado.nextDouble();
    y = teclado.nextDouble();
  }
  
  public boolean esVector()
  {
    return (x != 0 && y != 0);
  }
  
  public double encontrarMagnitud(double x, double y)
  {
    return Math.sqrt(x*x + y*y);
  }
  
  public double encontrarAngulo(double x, double y)
  {
    return Math.atan2(y,x);
  }
  
  public void imprimirVector()
  {
    System.out.printf("V%d: (x, y) = (", i);
    if (esEntero(x))
      System.out.printf("%d, ", (long)(x));
    else 
      System.out.printf("%.2f, ", (long)(x));
    if (esEntero(y))
      System.out.printf("%d); ", (long)(y));
    else
      System.out.printf("%.2f); ", (long)(y));
    System.out.printf("(r, <) = (", encontrarMagnitud(x,y), encontrarAngulo(x,y));
    if (esEntero(encontrarMagnitud(x,y)))
      System.out.printf("%d, ", (long)(encontrarMagnitud(x,y)));
    else 
      System.out.printf("%.2f, ", (encontrarMagnitud(x,y)));
    if (esEntero(encontrarAngulo(x,y)))
      System.out.printf("%d); ", (encontrarAngulo(x,y)));
    else
      System.out.printf("%.2f); ", (encontrarAngulo(x,y)));
    System.out.println();
  }
  
  public Vector sumaVectores(Vector nuevo)
  {
    Vector respuesta = new Vector();
    respuesta.x = x + nuevo.x;
    respuesta.y = y + nuevo.y;
    return respuesta;
  }
  
  public void imprimirSumaVectores()
  {
    System.out.printf("V%d + V%d: (x, y) = (", i-1, i);
    if (esEntero(x))
      System.out.printf("%d, ", (long)(x));
    else 
      System.out.printf("%.2f, ", (long)(x));
    if (esEntero(y))
      System.out.printf("%d); ", (long)(y));
    else
      System.out.printf("%.2f); ", (long)(y));
    System.out.printf("(r, <) = (", encontrarMagnitud(x,y), encontrarAngulo(x,y));
    if (esEntero(encontrarMagnitud(x,y)))
      System.out.printf("%d, ", (long)(encontrarMagnitud(x,y)));
    else 
      System.out.printf("%.2f, ", (encontrarMagnitud(x,y)));
    if (esEntero(encontrarAngulo(x,y)))
      System.out.printf("%d); ", (encontrarAngulo(x,y)));
    else
      System.out.printf("%.2f); ", (encontrarAngulo(x,y)));
    System.out.println();
    System.out.println();
  }
  
  public void imprimirrestaVectores1()
  {
    System.out.printf("V%d - V%d: (x, y) = (", i-1, i); 
    if (esEntero(x))
      System.out.printf("%d, ", (long)(x));
    else 
      System.out.printf("%.2f, ", (long)(x));
    if (esEntero(y))
      System.out.printf("%d); ", (long)(y));
    else
      System.out.printf("%.2f); ", (long)(y));
    System.out.printf("(r, <) = (", encontrarMagnitud(x,y), encontrarAngulo(x,y));
    if (esEntero(encontrarMagnitud(x,y)))
      System.out.printf("%d, ", (long)(encontrarMagnitud(x,y)));
    else 
      System.out.printf("%.2f, ", (encontrarMagnitud(x,y)));
    if (esEntero(encontrarAngulo(x,y)))
      System.out.printf("%d); ", (encontrarAngulo(x,y)));
    else
      System.out.printf("%.2f); ", (encontrarAngulo(x,y)));
    System.out.println();
    System.out.println();
  }
  
  public void imprimirrestaVectores2()
  {
    System.out.printf("V%d - V%d: (x, y) = (", i, i-1); 
    if (esEntero(x))
      System.out.printf("%d, ", (long)(x));
    else 
      System.out.printf("%.2f, ", (long)(x));
    if (esEntero(y))
      System.out.printf("%d); ", (long)(y));
    else
      System.out.printf("%.2f); ", (long)(y));
     System.out.printf("(r, <) = (", encontrarMagnitud(x,y), encontrarAngulo(x,y));
    if (esEntero(encontrarMagnitud(x,y)))
      System.out.printf("%d, ", (long)(encontrarMagnitud(x,y)));
    else 
      System.out.printf("%.2f, ", (encontrarMagnitud(x,y)));
    if (esEntero(encontrarAngulo(x,y)))
      System.out.printf("%d); ", (encontrarAngulo(x,y)));
    else
      System.out.printf("%.2f); ", (encontrarAngulo(x,y)));
    System.out.println();
    System.out.println();
  }
  
  public Vector restaVectores1(Vector nuevo)
  {
    Vector respuesta = new Vector();
    respuesta.x = x - nuevo.x;
    respuesta.y = y - nuevo.y;
    return respuesta;
  }
  
  public Vector restaVectores2(Vector nuevo)
  {
    Vector respuesta = new Vector();
    respuesta.x = nuevo.x - x;
    respuesta.y = nuevo.y - y;
    return respuesta;
  }
  
  public boolean esEntero(double n)
  {
    return ((long)(n) == n);
  }
}
