title: I am having trouble with user defined functions
body: <p>I am a beginner in programming and I had to write a program which accepts the coordinates of two points in 3D and find the distance between them and their midpoint using functions and objects, but for some reason the input that I am giving for the second object is also being initialized to my first object and I do not know where I am going wrong. I have wrote the program below</p>
  <pre><code>    import java.util.*; 
      class D3Point 
      {
      static double x,y,z;
      D3Point()
      {
          x=0.0;
          y=0.0;
          z=0.0;
      }
      static void acceptPoint()
      {
          Scanner sc=new Scanner(System.in);
          System.out.println(&quot;ENTER THE X-COORDINATE OF THE POINT&quot;);
          x=sc.nextDouble();
          System.out.println(&quot;ENTER THE Y-COORDINATE OF THE POINT&quot;);
          y=sc.nextDouble();
          System.out.println(&quot;ENTER THE Z-COORDINATE OF THE POINT&quot;);
          z=sc.nextDouble();
      }
      static void displayPoint()
      {
          System.out.println(&quot;(&quot;+x+&quot;,&quot;+y+&quot;,&quot;+z+&quot;)&quot;);
      }
      static double distance(D3Point P1, D3Point P2)
      {
          double a,b,c;
          double s,d;
          a=P2.x-P1.x;
          b=P2.y-P1.y;
          c=P2.z-P1.z;
          s=Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2);
          d=Math.sqrt(s);
          return d;
      }
      static D3Point midpoint(D3Point P1, D3Point P2)
      {
          D3Point P3= new D3Point();
          P3.x=(P1.x+P2.x)/2;
          P3.y=(P1.y+P2.y)/2;
          P3.z=(P1.z+P2.z)/2;
          return P3;
      }
      public static void main()
      {
          double d;
          D3Point Point1= new D3Point();
          D3Point Point2= new D3Point();
          D3Point Point3= new D3Point();
          Point1.acceptPoint();
          Point2.acceptPoint();
          System.out.println(&quot;THE COORDINATES OF THE TWO POINTS ARE:&quot;);
          Point1.displayPoint();
          Point2.displayPoint();
          d=distance(Point1, Point2);
          System.out.println(&quot;THE DISTANCE BETWEEN THE TWO POINTS IS =&quot;+d);
          Point3=midpoint(Point1, Point2);
          System.out.println(Point1.x);
          System.out.println(&quot;THE MIDPOINT OF THE TWO GIVEN POINT IS&quot;);
          Point3.displayPoint();
      } 
      }
  </code></pre>
  <p>The second input that I am giving for the object Point2 is also being initialized to the object Point1. I have posted a similar question but they were not much helpful as I did not explained the question properly. And I am not allowed to use String[] arghs or anything similiar as I have not been taught that yet.</p>