Advertisement
Guest User

teestessetset

a guest
Jan 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package lab1;
  7.  
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.io.IOException;
  11. import java.util.Arrays;
  12. import java.util.Scanner;
  13.  
  14. /**
  15. *
  16. * @author Gregory
  17. */
  18. public class Lab1 {
  19.  
  20. /**
  21. * @param args the command line arguments
  22. */
  23. public static void main(String[] args) throws FileNotFoundException {
  24.  
  25. try {
  26.  
  27. File file = new File("ELEVATIONS.txt");
  28. Scanner inputFile = new Scanner(file);
  29.  
  30. int rowsCount = 0;
  31. int colsCount = 0;
  32. int radius = 0;
  33.  
  34. if (inputFile.hasNext()) {
  35. rowsCount = inputFile.nextInt();
  36. } else {
  37. System.out.println("Error cannot read rows count");
  38. return;
  39. }
  40.  
  41. if (inputFile.hasNext()) {
  42. colsCount = inputFile.nextInt();
  43. } else {
  44. System.out.println("Error cannot read cols count");
  45. return;
  46. }
  47.  
  48. if (inputFile.hasNext()) {
  49. radius = inputFile.nextInt();
  50. } else {
  51. System.out.println("Error cannot read radius");
  52. return;
  53. }
  54.  
  55. int[][] numbers = new int[rowsCount][colsCount];
  56.  
  57. for (int row = 0; row < numbers.length; row++) {
  58. for (int col = 0; col < numbers[row].length; col++) {
  59. numbers[row][col] = inputFile.nextInt();
  60. }
  61. }
  62.  
  63. inputFile.close();
  64.  
  65. for (int row = 0; row < numbers.length; row++) {
  66. for (int col = 0; col < numbers[row].length; col++) {
  67. System.out.printf(numbers[row][col] + " ");
  68. }
  69. System.out.println();
  70. }
  71.  
  72. int[] lowestValueInData = lowestVal(numbers);
  73.  
  74. int[] allPeaks = localPeaks(numbers, radius);
  75.  
  76. System.out.println("the lowest data in the set is: " + lowestValueInData[0]);
  77. System.out.println("its frequency is: " + lowestValueInData[1] + " times.");
  78. System.out.println("all peaks: " + allPeaks);
  79.  
  80. //System.out.println("Local peaks: " localPeaks());
  81. } catch (IOException ex) {
  82. System.out.println(ex);
  83. }
  84.  
  85. }
  86.  
  87. public static int[] lowestVal(int numbers[][]) {
  88.  
  89. int lowestValue = numbers[0][0];
  90. int numOfTimes = 0;
  91.  
  92. for (int row = 0; row < numbers.length; row++) {
  93.  
  94. for (int col = 0; col < numbers[row].length; col++) {
  95.  
  96. if (numbers[row][col] < lowestValue) {
  97.  
  98. lowestValue = numbers[row][col];
  99.  
  100. numOfTimes = 1;
  101.  
  102. } else if (lowestValue == numbers[row][col]) {
  103.  
  104. numOfTimes++;
  105. }
  106.  
  107. }
  108.  
  109. }
  110.  
  111. return new int[]{lowestValue, numOfTimes};
  112. }
  113.  
  114. public static int[] localPeaks(int numbers[][], int radius) {
  115.  
  116. //int peaksArr[] = new int[0]; //?
  117.  
  118. //removes out of bounds exception, creates big square
  119. for (int rowTopLeft = radius; rowTopLeft < numbers.length - radius; rowTopLeft++) {
  120.  
  121. for (int colTopLeft = radius; colTopLeft < numbers[rowTopLeft].length - radius; colTopLeft++) {
  122.  
  123. int x = numbers[rowTopLeft][colTopLeft];
  124. if (x > 94850) { //if x is larger than 94850 search the radius otherwise skip
  125. //little square
  126. int[][] newStartPoint = numbers[rowTopLeft - radius][colTopLeft - radius];
  127.  
  128. for (int row = rowTopLeft; row < (rowTopLeft + radius * 2 + 1); row++) { //search radius of little square
  129.  
  130. for (int col = colTopLeft; col < (colTopLeft + radius * 2 + 1); col++) {
  131.  
  132. }
  133.  
  134. }
  135.  
  136. }
  137.  
  138. }
  139.  
  140. }
  141. }
  142.  
  143. }
  144.  
  145. // return peaksArr;
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement