import java.util.Scanner;

public class Vector
{
  private double x = 0.0;
  private double y = 0.0;
  private static Scanner teclado = new Scanner(System.in);
  
  public static void main(String args[])
  {
    System.out.println("Operaciones con vectores en el plano");
    
    Vector v1 = null;
    Vector v2 = new Vector();
    
    for (int contador=1; ; ++contador)
    {
      System.out.print("Vector " + contador + ": ");
      if(! v2.leer() )
        return;
      System.out.println("\nV" + contador + ": " + v2.toString());
      System.out.println();
      
      
      if(v1!=null)
      {
        Vector vSuma = v1.sumar(v2);
        System.out.println("V" + (contador-1) + " + " + "V" + contador + ": " + vSuma.toString());
        
        Vector vResta1 = v1.restar(v2);
        System.out.println("V" + (contador-1) + " - " + "V" + contador + ": " + vResta1.toString());
        
        Vector vResta2 = v2.restar(v1);
        System.out.println("V" + contador + " - " + "V" + (contador-1) + ": " + vResta2.toString());
      } 
      v1 = v2;
      v2 = new Vector();
      
    }//for
    
  }//main()
  
  
  public boolean leer()
  {
    System.out.print("x: ");
    x = teclado.nextDouble();
    
    System.out.print("y: ");
    y = teclado.nextDouble();
    
    if(x==0 && y==0)
      return false;
    else return true;
  }//leer
  
  
  public String toString()
  {
    return "(x, y) = " + "(" + x + ", " + y + "); (r, &) = (" + magnitud(x,y) + ", " + radianes(y,x) + ")";
  }//toString
  
  
  public double magnitud(double x, double y)
  {
    return Math.sqrt(x*x+y*y); 
  }//magnitud
  
  
  public double radianes(double y, double x)
  {
    return Math.atan2(y, x); 
  }//radianes
  
  
  public Vector sumar(Vector otra)
  {
    Vector sumado = new Vector();
    sumado.x = this.x + otra.x;
    sumado.y = this.y + otra.y;
    return sumado;
  }//sumar
  
  public Vector restar(Vector otra)
  {
    Vector restado = new Vector();
    restado.x  = this.x - otra.x;
    restado.y = this.y - otra.y;
    return restado;
  }//restar
  
  
}//class