title: Calculate Euclidean Distance Between Two Points Using Constructor
body: <p>I'm working on an assignment to write a java program which implements a Point data type with the following constructor:</p>
  <p>Point(double x, double y, double z)</p>
  <p>and, the following API:</p>
  <ul>
  <li><p>double distanceto(Point q)
  it returns the Euclidean distance between this and q.
  The Euclidean distance between (x1, y1, z1) and (x2, y2, z2) is defined as sqrt( (x1-x2)^2 + (y1-y2)^2) + (z1-z2)^2).</p>
  </li>
  <li><p>String toString() – it returns the string representation of the point. An example would be (2.3,4.5,3.0).</p>
  </li>
  <li><p>Write a main method in the class that is used to test it.
  It should create two Point objects using input provided by the user on the command-line.
  Then it should print out the two points followed by their Euclidean distance
  A sample run would be as follows.</p>
  </li>
  </ul>
  <p>java Point 2.1 3.0 3.5 4 5.2 3.5</p>
  <p>The first point is (2.1,3.0,3.5)</p>
  <p>The second point is (4.0,5.2,3.5)</p>
  <p>Their Euclidean distance is 2.90</p>
  <p>The program won't compile, but I'm not sure why. I'm new to programming, so I followed some steps from online and Codecademy to try and access objects in the constructor, but I think I'm doing it wrong. Any suggestions would be greatly appreciated.</p>
  <pre><code>public class Point {
      double x1;
      double y1;
      double z1;
      double x2;
      double y2;
      double z2;
      
      public Point(double x, double y, double z){
  
          x1 = x;
          y1 = y;
          z1 = z;
          x2 = x;
          y2 = y;
          z2 = z;
      }
      
      public double distanceTo(Point q){
      return Math.sqrt(Math.pow((x1-x2), 2.0) + Math.pow((y1-y2), 2.0) + Math.pow((z1-z2), 2.0));
      
      }
      double x3 = x1-x2;
      double y3 = y1-y2;
      double z3 = z1-z2;
  
      public String toString() {
          return &quot;(&quot; + x3 + &quot;, &quot; + y3 + &quot;, &quot; + z3 + &quot;)&quot;;
      }
      
      public static void main (String[]args){
          
          Point pointOne = new Point(args[0]);
          Point pointTwo = new Point(args[1]);
          Point distance = new distanceTo();
          
          System.out.println(&quot;The first point is &quot; + &quot;(&quot; + pointOne + &quot;)&quot;);
          System.out.println(&quot;The second point is &quot; + &quot;(&quot; + pointTwo + &quot;)&quot;);
          System.out.println(&quot;Their Euclidean distance is &quot; + distance);
      }
  }
  </code></pre>