Advertisement
sudoaptinstallname

Untitled

Jan 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package com.company;
  2. /*
  3. Object Class
  4. */
  5.  
  6. public class Point {
  7. private int x;
  8. private int y;
  9.  
  10. public Point() //default constructor
  11. {
  12. x = 0;
  13. y = 0;
  14. }
  15.  
  16. public Point(int x1, int y1) {
  17. if (x1 >= 0 || y1 >= 0) {
  18. x = x1;
  19. y = y1;
  20. } else {
  21. x = 0;
  22. y = 0;
  23. }
  24. }
  25.  
  26. public void setX(int x1) //Mutator Method
  27. {
  28. x = x1;
  29. }
  30.  
  31. public void setY(int y1) //Mutator method
  32. {
  33. y = y1;
  34. }
  35.  
  36. public int getX() //Assesor Method
  37. {
  38. return x;
  39. }
  40.  
  41. public int getY() //Assesor method
  42. {
  43. return y;
  44. }
  45.  
  46. public double DistanceToOrigin() // nonstaic method that returns values to the main program
  47. {
  48. return (Math.sqrt(x * x + y * y));
  49. }
  50.  
  51. public void PrintPoint() // nonstatic method we must make an object reference
  52. {
  53. System.out.println(" Point p1 = (" + x + " , " + y + " )");
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement