Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class Point {
  2.  
  3. // Params
  4. private int x;
  5. private int y;
  6.  
  7. // Constructors
  8. public Point() {
  9. this(0,0);
  10. }
  11. public Point(int x, int y) {
  12. this.x = x;
  13. this.y = y;
  14. }
  15.  
  16. // Getters
  17. public int getX() {
  18. return x;
  19. }
  20. public int getY() {
  21. return y;
  22. }
  23.  
  24. // Setters
  25. public void setX(int x) {
  26. this.x = x;
  27. }
  28. public void setY(int y) {
  29. this.y = y;
  30. }
  31.  
  32. // Extra Methods
  33. public double distance (){
  34. return distance(0,0);
  35. }
  36. public double distance(int x,int y){
  37. return Math.sqrt(Math.pow(this.x - x, 2) + Math.pow(this.y - y, 2));
  38. }
  39. public double distance(Point newPoint){
  40. return distance(newPoint.x,newPoint.y);
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement