Advertisement
dorirozs

Untitled

Dec 7th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. class ConvexHull{
  5.  
  6.  
  7. public static int loadPoints(int maxPoints, double[] xVal, double[] yVal){
  8. Scanner scan = new Scanner(System.in);
  9. System.out.println("Input: ");
  10. double num = 0;
  11. int counter = 0;
  12. boolean alter = false;
  13.  
  14.  
  15. while (scan.hasNext()) {
  16.  
  17. num = scan.nextDouble();
  18. if (num < 0) {
  19. return counter;
  20. }
  21. if (counter > 2*maxPoints ) return counter;
  22. if (alter){
  23. yVal[counter] = num;
  24. counter++;
  25. alter = false;
  26. } else {
  27. xVal[counter] = num;
  28. alter = true;
  29. }
  30.  
  31. }
  32.  
  33. return counter;
  34. }
  35. /*public static boolean checkDuplicates(int pointCount, double xVal[], double yVal[]){
  36.  
  37. /* public static void computeConvexHull(int pointCount, double xVal[], double yVal[]){
  38.  
  39. double m, c;
  40. put your code here
  41.  
  42.  
  43. for (int i=pointCount; i>=1; i--) {
  44. for (int j=0; j<i; j++) {
  45. if(i != j) {
  46. if(xVal[i] == xVal[j] && yVal[i] == yVal[j]) {
  47. System.out.println("Error: There are duplicates.")
  48. return true;
  49. }
  50. }
  51.  
  52. }
  53. }
  54. return false;
  55. }
  56. */
  57.  
  58.  
  59. public static void main(String[] args) {
  60.  
  61. int maxPoints = 70;
  62. double xVal[] = new double[maxPoints];
  63. double yVal[] = new double[maxPoints];
  64.  
  65. int pointCount = loadPoints(maxPoints, xVal, yVal);
  66. System.out.println(pointCount);
  67.  
  68.  
  69. for (int i=0; i < maxPoints; i++) {
  70. if (xVal[i] != 0) {
  71. System.out.println("("+ xVal[i] + "," + yVal[i] +")");
  72. }
  73. }
  74. // if ( checkDuplicates(pointCount, xVal, yVal) ) return;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement