Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. class Point2D {
  2. int x, y;
  3.  
  4. public Point2D(int x, int y) {
  5. this.x = x;
  6. this.y = y;
  7. }
  8.  
  9. double dist2D(Point2D p) {
  10. return (int)(Math.ceil( (float) Math.sqrt( (p.x - this.x) * (p.x - this.x) + (p.y - this.y) * (p.y - this.y) )));
  11. }
  12.  
  13. void printDistance(double d) {
  14. System.out.println("2D distance = " + (int)d);
  15. }
  16. }
  17.  
  18. class Point3D extends Point2D {
  19. int z;
  20. public Point3D(int x, int y) {
  21. this(x, y, 0);
  22. }
  23. public Point3D(int x, int y, int z) {
  24. super(x, y);
  25. this.z = z;
  26. }
  27. double dist3D(Point3D p) {
  28. return (int) (Math.ceil( (float) Math.sqrt( (p.x - this.x) * (p.x - this.x) + (p.y - this.y) * (p.y - this.y) + (p.z - this.z) * (p.z - this.z) )));
  29. }
  30. void printDistance(double d) {
  31. System.out.println("3D distance = " + (int)d);
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement