Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1.  
  2. import javafx.geometry.Point2D;
  3.  
  4. public class Point2D_2 {
  5.  
  6. // Main Method
  7. public static void main(String args[])
  8. {
  9.  
  10. // Create three point2D objects
  11. Point2D point2d_1 = new Point2D(120.0f, 50.0f);
  12. Point2D point2d_2 = new Point2D(120.0f, 50.0f);
  13. Point2D point2d_3 = new Point2D(200.0f, 120.0f);
  14.  
  15. // Display the coordinates of the 3 points
  16. display(point2d_1);
  17. display(point2d_2);
  18. display(point2d_3);
  19.  
  20. // Check whether any point is equal to other or not
  21. System.out.println("Point 1 equals Point 2 = "
  22. + point2d_1.equals(point2d_2));
  23.  
  24. System.out.println("Point 2 equals Point 3 = "
  25. + point2d_2.equals(point2d_3));
  26.  
  27. System.out.println("Point 3 equals Point 1 = "
  28. + point2d_3.equals(point2d_1));
  29.  
  30. // distance between two points
  31. System.out.println("Distane between point 1 and point 2 = "
  32. + point2d_1.distance(point2d_2));
  33.  
  34. System.out.println("Distane between point 2 and point 3 = "
  35. + point2d_2.distance(point2d_3));
  36.  
  37. System.out.println("Distane between point 3 and point 1 = "
  38. + point2d_3.distance(point2d_1));
  39. }
  40.  
  41. // display method
  42. public static void display(Point2D point2d)
  43. {
  44.  
  45. double x, y;
  46.  
  47. // get the coordinates of the point
  48. x = point2d.getX();
  49. y = point2d.getY();
  50.  
  51. // display the coordinates of the point
  52. System.out.println("x coordinate = " + x
  53. + ", y coordinate = " + y);
  54.  
  55. // print its distance from origin
  56. System.out.println("Distance from origin = "
  57. + point2d.distance(0, 0));
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement