import java.util.Scanner;

public class Vectores
  
{
  static double x=0;
  static double y=0;
  static double x0=0;
  static double y0=0;
  public static void main (String args[])
  {
    
    System.out.println("Operaciones con vectores en el plano");
    for (int n=1 ; ; ++n)
    {
      if (LeerVectores(n) == false)
        break;
      else
      {
         System.out.println("V" + n + "= (x,y)= (" + x + "," + y+ "); (r,an) = (" + CalcularMagnitud(x,y) + ","+ CalcularDireccion(x,y)+ ") \n");
        
        if (n>1)
        {
          SumarVectores (n,x0,y0,x,y);
          RestarVectores (n,x0,y0,x,y); 
        }
      }
      x0=x;
      y0=y;
    }
    
  }
  
  
  public static boolean LeerVectores(int n)
  {
    Scanner teclado= new Scanner(System.in);
    System.out.println("Vector " + n);
    System.out.print("x: ");
    x= teclado.nextDouble();
    System.out.print("y: ");
    y=teclado.nextDouble();
    
    if (x !=0 && y!=0)
      return true;
    else return false;
  }
  public static double CalcularMagnitud(double x, double y)
  {
    double x2= x*x;
    double y2= y*y;
    double r= Math.sqrt(x2+y2);
    return r;
  }
  public static double CalcularDireccion (double x, double y)
  {
    //an=angulo
    double an = Math.atan2(x,y);
    return an ;
  }
  public static void SumarVectores (int n,double x0, double y0, double x, double y)
  {
    double sumaX= x0+x;
    double sumaY= y0+y;
    x= sumaX;
    y= sumaY;      
    System.out.println("V" + (n-1) + "+" + "V" + n + "= (x,y)= (" + x + "," + y+ "); (r,an) = (" + CalcularMagnitud(x,y) + ","+ CalcularDireccion(x,y)+ ") ");
  }
  public static void RestarVectores (int n, double x0, double y0, double x, double y)
  {
    
    double restaX= x0-x;
    double restaY= y0-y;
    double resta2X= x-x0;
    double resta2Y= y-y0;
    
    x= restaX;
    y= restaY;
    System.out.println("V" + (n-1) + "-" + "V" + n + "= (x,y)= (" + x + "," + y + "); (r,an) = (" + CalcularMagnitud(x,y) + ","+ CalcularDireccion(x,y)+ ") ");
    x= resta2X;
    y= resta2Y;
    System.out.println("V" + (n) + "-" + "V" + (n-1) + "= (x,y)= (" + x + "," + y+ "); (r,an) = (" + CalcularMagnitud(x,y) + ","+ CalcularDireccion(x,y)+ ") ");
    
  }
  
  
}

