import java.io.*;


public class TestPXYZ  {

   private static void pause() {
    try {
      System.in.read();
    }
    catch (IOException e) {
    }
  }  // pause

  private static void  test1() {
    PX p1, p2, p3;
    p1 = new PX(11);
    p2 = new PX(22,"p2");
    p3 = new PX( p1 );
    p3.addX(-3);
    p3.setName("p3");

    System.out.println( p1 );
    System.out.println( p2 );
    System.out.println( p3 );
    System.out.println( "Abstand p1 zu p2: "+p1.getDistance(p2) );
  }

  private static void  test2() {
    PXY p1, p2, p3;
    p1 = new PXY(11,22);
    p2 = new PXY(33,44,"p2");
    p3 = new PXY( p1 );
    p3.addX(-3);
    p3.addY(+1);
    p3.setName("p3");

    System.out.println( p1 );
    System.out.println( p2 );
    System.out.println( p3 );
    System.out.println( "Abstand p1 zu p2: "+p1.getDistance(p2) );
  }

  private static void  test3() {
    PXYZ p1, p2, p3;
    p1 = new PXYZ(1,2,3);
    p2 = new PXYZ(3,4,5,"p2");
    p3 = new PXYZ( p1 );
    p3.addX(-3);
    p3.addY(+1);
    p3.addZ(+2);
    p3.setName("p3");

    System.out.println( p1 );
    System.out.println( p2 );
    System.out.println( p3 );
    System.out.println( "Abstand p1 zu p2: "+p1.getDistance(p2) );
  }

  public static void main(String[] args) {
    test3();
    pause();
  }
}

// ---------------------------------------
// ---------------------------------------
// ---------------------------------------
// ---------------------------------------

abstract class P0 {
    abstract public String toString();
    abstract public double getDistance(Object obj);
}

// -----------------------------------------
// -----------------------------------------

class PX  extends P0 {
  protected int x;
  protected String name;

  public PX(int x) {
    this(x,"noname");
  }

  public PX(int x, String name) {
    this.x=x;
    this.name = name;
  }

  public PX(PX p) {
    x=p.x;
    this.name = p.name;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public void addX(int deltax) {
    this.x+=deltax;
  }

  public int getX() {
    return x;
  }

  public String toString() {
    return "Name: "+name+"  Value x: "+x;
  }

  public double getDistance(Object obj) {
    PX p = (PX) obj;
    double d1 = this.x - p.x;
    return d1;
  }


}  // PX


// ---------------------------------------
// ---------------------------------------
// ---------------------------------------
// ---------------------------------------
class PXY  extends PX {
  protected int y;

  public PXY() {
    this(1,1,"");
  }

  public PXY(int x, int y) {
    this(x,y,"");
  }
  public PXY(int x, int y, String name) {
    super(x,name);
    this.y=y;
  }

  public PXY(PXY p) {
    super( (PX) p);
    y=p.y;
  }

  public double getDistance(Object obj) {
    PXY p = (PXY) obj;
    double d1 = this.x - p.x;
    double d2 = this.y - p.y;
    double erg = Math.sqrt(   d1*d1 + d2*d2);
    return erg;
  }



  public void addY(int deltay) {
    this.y+=deltay;
  }

  public int getY() {
    return y;
  }


  public String toString() {
    return super.toString() + "  Value y: "+y;
  }

} // PXY


// ---------------------------------------
// ---------------------------------------
// ---------------------------------------
// ---------------------------------------
class PXYZ  extends PXY {
  protected int z;

  public PXYZ() {
    this(1,1,1,"");
  }

  public PXYZ(int x, int y,int z) {
    this(x,y,z,"");
  }
  public PXYZ(int x, int y, int z, String name) {
    super(x,y,name);
    this.z=z;
  }

  public PXYZ(PXYZ p) {
    super( (PXYZ) p);
    z=p.z;
  }

  public double getDistance(Object obj) {
    PXYZ p = (PXYZ) obj;
    double d1 = this.x - p.x;
    double d2 = this.y - p.y;
    double d3 = this.y - p.y;
    double erg = Math.sqrt(   d1*d1 + d2*d2+ d3*d3);
    return erg;
  }



  public void addZ(int deltaz) {
    this.z+=deltaz;
  }

  public int getZ() {
    return z;
  }


  public String toString() {
    return super.toString() + "  Value z: "+z;
  }

} // PXYZ

