Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public class MyPointTest {
  2. /** Main method */
  3. public static void main(String[] args) {
  4.  
  5.  
  6. MyPoint a = new MyPoint (0, 0);
  7. MyPoint b = new MyPoint (3, 4);
  8.  
  9. // Create Distance object
  10. double d = a.distance(b);
  11. // Display distance
  12. System.out.printf(
  13. "The distance of that point from the origin is %.2f\n",
  14. d);
  15.  
  16. }
  17. }
  18. class MyPoint {
  19. private double x;
  20. private double y;
  21.  
  22. public MyPoint( ) {
  23. this(0, 0);
  24. }
  25.  
  26. public MyPoint(double x, double y) {
  27. this.x = x;
  28. this.y = y;
  29. }
  30.  
  31. public double getX() {
  32. return x;
  33. }
  34. public void setX(double x) {
  35. this.x = x;
  36. }
  37. public double getY() {
  38. return y;
  39. }
  40. public void setY(double y) {
  41. this.y = y;
  42. }
  43. public double distance(MyPoint pointB) {
  44. return Math.sqrt(Math.pow(pointB.getX - this.getX, 2) + Math.pow(pointB.getY() - this.getY(), 2));
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement