Advertisement
Guest User

ADT Point

a guest
Apr 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. class Point {
  2. float x;
  3. float y;
  4. }
  5.  
  6. public class ADT_KelompokVandiPoint {
  7. static Point makePoint(float x, float y){
  8. Point A = new Point();
  9. A.x = x;
  10. A.y = y;
  11. return A;
  12. }
  13.  
  14. static Point bacaPoint(){
  15. Point A = new Point();
  16. A.x = 9.3f;
  17. A.y = 3.6f;
  18. return A;
  19. }
  20.  
  21. static float getAbsis(Point A){
  22. return A.x;
  23. }
  24.  
  25. static float getOrdinat(Point A){
  26. return A.y;
  27. }
  28.  
  29. static void setAbsis(Point A, float x){
  30. A.x = x;
  31. }
  32.  
  33. static void setOrdinat(Point A, float y){
  34. A.y = y;
  35. }
  36.  
  37. static void tulisPoint(Point A){
  38. System.out.println("Point ("+A.x+","+A.y+") dengan x = "+A.x+" dan y = "+A.y);
  39. }
  40.  
  41. static Point geserKanan(Point A, float dx){
  42. A.x += dx;
  43. return A;
  44. }
  45.  
  46. static Point geserAtas(Point A, float dy){
  47. A.y += dy;
  48. return A;
  49. }
  50.  
  51. static Point cerminX(Point A){
  52. A.y = -A.y;
  53. return A;
  54. }
  55.  
  56. static Point cerminY(Point A){
  57. A.x = -A.x;
  58. return A;
  59. }
  60.  
  61. public static void main(String[] args){
  62. Point P1 = makePoint(4,6);
  63. Point P2 = bacaPoint();
  64. tulisPoint(P1);
  65. tulisPoint(P2);
  66. float x = getAbsis(P1);
  67. float y = getOrdinat(P1);
  68. setAbsis(P1,4);
  69. setOrdinat(P1,6);
  70. tulisPoint(P1);
  71. P1= geserKanan(P1,5);
  72. tulisPoint(P1);
  73. P1 = geserAtas(P1,7);
  74. tulisPoint(P1);
  75. P1 = cerminX(P1);
  76. tulisPoint(P1);
  77. P1 = cerminY(P1);
  78. tulisPoint(P1);
  79.  
  80. }
  81. }
  82.  
  83. HASIL :
  84.  
  85. Point (4.0,6.0) dengan x = 4.0 dan y = 6.0
  86. Point (9.3,3.6) dengan x = 9.3 dan y = 3.6
  87. Point (4.0,6.0) dengan x = 4.0 dan y = 6.0
  88. Point (9.0,6.0) dengan x = 9.0 dan y = 6.0
  89. Point (9.0,13.0) dengan x = 9.0 dan y = 13.0
  90. Point (9.0,-13.0) dengan x = 9.0 dan y = -13.0
  91. Point (-9.0,-13.0) dengan x = -9.0 dan y = -13.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement