Advertisement
kmahadev

Point Class

Aug 25th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1.  
  2. public class Point {
  3.  
  4. public int x;
  5. public int y;
  6.  
  7. public Point() {
  8. this.x = 0;
  9. this.y = 0;
  10. }
  11.  
  12. public Point(int x, int y) {
  13. this.x = x;
  14. this.y = y;
  15. }
  16.  
  17. /**
  18. * @return the x
  19. */
  20. public int getX() {
  21. return x;
  22. }
  23.  
  24. /**
  25. * @param x the x to set
  26. */
  27. public void setX(int x) {
  28. this.x = x;
  29. }
  30.  
  31. /**
  32. * @return the y
  33. */
  34. public int getY() {
  35. return y;
  36. }
  37.  
  38. /**
  39. * @param y the y to set
  40. */
  41. public void setY(int y) {
  42. this.y = y;
  43. }
  44.  
  45. public double distanceFormula(Point p1, Point p2) {
  46. double distance;
  47. distance = Math.sqrt( ( (p1.getX() - p2.getX()) * (p1.getX() - p2.getX() ) +
  48. (p1.getY() - p2.getY()) * (p1.getY() - p2.getY() )
  49. ) ) ;
  50. return distance;
  51. }
  52.  
  53. public String toString() {
  54. return this.getClass().getName() + " is: ( " + this.getX() + ", " + this.getY() + " )";
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement