Advertisement
Guest User

ADT Garis

a guest
Apr 23rd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. class Point2 {
  2. float x;
  3. float y;
  4. }
  5.  
  6. class Line {
  7. Point2 awal;
  8. Point2 akhir;
  9. }
  10.  
  11. public class ADTGaris {
  12.  
  13. static Point2 makePoint(float x, float y){
  14. Point2 temp = new Point2();
  15. temp.x = x;
  16. temp.y = y;
  17. return temp;
  18. }
  19.  
  20. static Line makeLine(Point2 a, Point2 b){
  21. Line temp = new Line();
  22. temp.awal = a;
  23. temp.akhir = b;
  24. return temp;
  25. }
  26.  
  27. static float distanceX(Point2 a, Point2 b){
  28. return b.x - a.x;
  29. }
  30.  
  31. static float distanceY(Point2 a, Point2 b){
  32. return b.y - a.y;
  33. }
  34.  
  35. static float gradient(Point2 a, Point2 b){
  36. return (b.y - a.y)/(b.x - a.x);
  37. }
  38.  
  39. static void writeLine(Line a){
  40. System.out.println("Point awal : "+a.awal.x+" , "+a.awal.y+"\nPoint akhir : "+a.akhir.x+" , "+a.akhir.y);
  41. }
  42.  
  43. public static void main(String[] args){
  44. Point2 a = makePoint(1, 2);
  45. Point2 b = makePoint(3, 4);
  46. Line l = makeLine(a, b);
  47.  
  48. writeLine(l);
  49.  
  50. System.out.println("Jarak X : "+distanceX(a, b)+"\nJarak Y : "+distanceY(a, b));
  51. System.out.println("Gradien garis : "+gradient(a, b));
  52. }
  53. }
  54.  
  55. HASIL :
  56.  
  57. Point awal : 1.0 , 2.0
  58. Point akhir : 3.0 , 4.0
  59. Jarak X : 2.0
  60. Jarak Y : 2.0
  61. Gradien garis : 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement