Thursday, December 11, 2014

[Java] How do you create a Point2D? Suppose p1 and p2 are two instances of Point2D? How do you obtain the distance between the two points?

You can create a Point2D by import the class javafx.geometry.Point2D, and then create a Point2D Object by calling the Point2D constructor with x and y coordinates. And there is the example to create instance two instances named p1 and p2 of Point2D :
    Point2D p1 = new Point2D (1.2,2.0);
    Point2D p2 = new Point2D (3,5);
To obtain the distance between two points, we can call distance() method to calculate :
    System.out.println(“The distance between Point2D p1 and p2 is ”+ p1.distance(p2));
Remarks
Text provided above does not means is the model answer, and it's was posted here for an reference to somebody who interested the related knowledge only. if there is something incorrect, please leave a comment so that i can correct it or for others viewer to have an better reference, if you want know more about this topic and where is the question, concept or answer from, you can reference from information provided under the reference sub-title.

Reference:
Introduction to Java Programming, Y. Daniel Liang 9.15

No comments :

Post a Comment