public class Vector
  
{
  public static int n=1;
  public double vectorx = 0.0;
  public double vectory = 0.0;
  
  public static void main(String args[])
  {
    Vector vector1= null;
    Vector vector2 = new Vector();
    
    while (true)
    {
      if (! vector2.leer())
        return;
      System.out.println(vector2);
      System.out.println();
      if (n>1)
      {
        vector2.imprimirSumar(vector1);
        vector2.imprimirRestar(vector1);
        vector2.imprimirRestarReciproca(vector1);
      }
      vector1= vector2;
      vector2= new Vector();
      ++n;
    }
  }
  
  public boolean leer()
  {
    System.out.println("Vector "+n+":");
    vectorx = Keyboard.getNextDouble("vector x: ");
    vectory = Keyboard.getNextDouble("vector y: ");
    if (vectorx==0.0 && vectory==0.0)
      return false;
    else
      return true;
  }
  
  public String toString()
  {
    return "V"+n+": (x, y)= ("+vectorx+", "+vectory+"); (r, angulo)= ("+calcularNorma()+", "+calcularAngulo()+")";
  }
  
  public double calcularNorma()
  {
    return Math.sqrt(vectorx*vectorx+vectory*vectory);
  }
  
  public double calcularAngulo()
  {
    return Math.atan2(vectorx,vectory);
  }
  
  public void imprimirSumar(Vector otro)
  {
    double sumaX = vectorx + otro.vectorx ;
    double sumaY = vectory + otro.vectory ;
    
    System.out.println("V"+(n-1)+" + V"+n+": (x, y)= ("+sumaX+", "+sumaY+"); (r, angulo)= ("+
                       Math.sqrt(sumaX*sumaX+sumaY*sumaY)+", "+Math.atan2(sumaX,sumaY)+")");
  }
  
  public void imprimirRestar(Vector otro)
  {
    double restaX = otro.vectorx - vectorx ;
    double restaY = otro.vectory - vectory ;
    
    System.out.println("V"+(n-1)+" + V"+n+": (x, y)= ("+restaX+", "+restaY+"); (r, angulo)= ("+
                       Math.sqrt(restaX*restaX+restaY*restaY)+", "+Math.atan2(restaX,restaY)+")");
  }
  
  public void imprimirRestarReciproca(Vector otro)
  {
    double restaReciprocaX = vectorx - otro.vectorx ;
    double restaReciprocaY = otro.vectory - vectory ;
    
    System.out.println("V"+(n)+" + V"+(n-1)+": (x, y)= ("+restaReciprocaX+", "+restaReciprocaY+"); (r, angulo)= ("+
                       Math.sqrt(restaReciprocaX*restaReciprocaX+restaReciprocaY*restaReciprocaY)+", "+Math.atan2(restaReciprocaX,restaReciprocaY)+")");
  }
  
  
}
