Guest User

להגשה 1-4

a guest
Nov 13th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Point_actions
  3. {
  4.  
  5.  
  6.  
  7.  
  8. static Scanner scan = new Scanner(System.in);
  9.  
  10. //משימה 4
  11. //addLast
  12. //איבר כללי ורשימה כללית ???
  13. //מה זה איך מתעסקים עם זה ואיזה פעולות יש לזה
  14. // ברשימה בשאלות להגשה אם היא מתכוונת לNODE או שהיא מתכוונת לLIST
  15. //public static void addLast()
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. // משימה 3
  25. public static Point minX(Node<Point> first)
  26. {
  27.  
  28. Node<Point>tmp = first;
  29. Point p = first.getValue();
  30. double X =tmp.getValue().getxPos();
  31. while(tmp != null)
  32. {
  33. if(tmp.getValue().getxPos() < X)
  34. {
  35. X = tmp.getValue().getxPos();
  36. p = tmp.getValue();
  37. }
  38. tmp=tmp.getNext();
  39. }
  40. return p;
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. // משימה 2
  54. public static int countPos(Node<Point> first)
  55. {
  56. int count =0;
  57. Node<Point>tmp = first;
  58. while(tmp != null)
  59. {
  60. if(tmp.getValue().getxPos() > 0 && tmp.getValue().getyPos() > 0){
  61. count++;
  62. }
  63. tmp=tmp.getNext();
  64. }
  65. return count;
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. // משימה 1
  74. public static Node<Point> createPointList()
  75. {
  76. System.out.println("Enter the amount of Points in the List");
  77. int length =scan.nextInt();
  78. System.out.println("Enter the p's X : ");
  79. double X = scan.nextInt();
  80. System.out.println("Enter the p's Y : ");
  81. double Y = scan.nextInt();
  82. Point p =new Point(X,Y);
  83. Node<Point> first =new Node<Point>(p);
  84. Node<Point>tmp =first;
  85. for(int i=1; i<length; i++)
  86. {
  87. System.out.println("Enter the p's X : ");
  88. X = scan.nextInt();
  89. System.out.println("Enter the p's Y : ");
  90. Y = scan.nextInt();
  91. Point P =new Point(X,Y);
  92. Node<Point> S =new Node<Point>(P);
  93. tmp.setNext(S);
  94. tmp = S;
  95. }
  96. return first;
  97.  
  98. }
  99. //פעולה המדפיסה את הרשימה
  100. public static void print(Node node)
  101. {
  102. while(node !=null)
  103. {
  104. System.out.println(node);
  105. node = node.getNext();
  106. }
  107. }
  108.  
  109.  
  110. public static void main(String[]args)
  111. {
  112.  
  113. //print(createPointList());
  114.  
  115. //System.out.println(countPos(createPointList()));
  116.  
  117. System.out.println(minX(createPointList()));
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment