Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.70 KB | None | 0 0
  1. import java.io.File;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.util.Collections;
  5. import java.util.Comparator;
  6. import java.util.Scanner;
  7.  
  8. public class GISRunner {
  9.  
  10. /**
  11. * @param args
  12. */
  13. public static void main(String[] args) throws FileNotFoundException {
  14. File file = new File("GIS.txt");
  15. Scanner input = new Scanner(file);
  16. String[] lineData = null;
  17. String lineRaw = null;
  18. String featureName, featureClass, stateCode, countyName, primaryLatitudeDMS, primaryLongitudeDMS,
  19. sourceLatitudeDMS, sourceLongitudeDMS, mapName;
  20. Integer featureId, stateId, countyId, elevationMeters, elevationFeet;
  21. Double primaryLatitudeDecimal, primaryLongitudeDecimal, sourceLatitudeDecimal, sourceLongitudeDecimal;
  22.  
  23. GISDataStructure datas = new GISDataStructure();
  24. while (input.hasNext()) {
  25. lineRaw = input.nextLine();
  26. lineData = lineRaw.split("\|");
  27. featureId = 0;
  28. try {
  29. featureId = Integer.valueOf(lineData[0]);
  30. } catch (NumberFormatException e) {
  31. featureId = Integer.valueOf(lineData[0].substring(3));
  32. }
  33. featureName = lineData[1];
  34. featureClass = lineData[2];
  35. stateCode = lineData[3];
  36. stateId = Integer.valueOf(lineData[4]);
  37. countyName = lineData[5];
  38. try {
  39. countyId = Integer.valueOf(lineData[6]);
  40. } catch (NumberFormatException e2) {
  41. countyId = null;
  42. }
  43. primaryLatitudeDMS = lineData[7];
  44. primaryLongitudeDMS = lineData[8];
  45. primaryLatitudeDecimal = Double.valueOf(lineData[9]);
  46. primaryLongitudeDecimal = Double.valueOf(lineData[10]);
  47. sourceLatitudeDMS = lineData[11];
  48. sourceLongitudeDMS = lineData[12];
  49. try {
  50. sourceLatitudeDecimal = Double.valueOf(lineData[13]);
  51. } catch (NumberFormatException e1) {
  52. sourceLatitudeDecimal = null;
  53. }
  54. try {
  55. sourceLongitudeDecimal = Double.valueOf(lineData[14]);
  56. } catch (NumberFormatException e1) {
  57. sourceLongitudeDecimal = null;
  58. }
  59. try {
  60. elevationMeters = Integer.valueOf(lineData[15]);
  61. } catch (NumberFormatException e) {
  62. elevationMeters = null;
  63. }
  64. try {
  65. elevationFeet = Integer.valueOf(lineData[16]);
  66. } catch (NumberFormatException e) {
  67. elevationFeet = null;
  68. }
  69. mapName = lineData[17];
  70.  
  71. GISData newGISData = new GISData(featureId, featureName, featureClass, stateCode, stateId, countyName,
  72. countyId, primaryLatitudeDMS, primaryLongitudeDMS, primaryLatitudeDecimal, primaryLongitudeDecimal,
  73. sourceLatitudeDMS, sourceLongitudeDMS, sourceLatitudeDecimal, sourceLongitudeDecimal,
  74. elevationMeters, elevationFeet, mapName);
  75. datas.insert(newGISData);
  76. }
  77. System.out.println(datas.toString());
  78. input.close();
  79.  
  80. Collections.sort(datas);
  81. }
  82. }
  83.  
  84.  
  85. import java.util.ArrayList;
  86. import java.util.Collections;
  87. import java.util.Comparator;
  88. import java.util.Scanner;
  89.  
  90. import edu.matc.itdev154.finalexam.GISData.SortByType;
  91.  
  92. public class GISDataStructure {
  93.  
  94. private static Scanner sc = new Scanner(System.in);
  95.  
  96. public ArrayList<GISData> data;
  97.  
  98. public GISDataStructure() {
  99. data = new ArrayList<GISData>();
  100. }
  101.  
  102. public void insert(GISData element) {
  103. data.add(element);
  104. }
  105.  
  106. public static void searchData(ArrayList<GISData> data) {
  107. String state;
  108. GISData foundData = null;
  109.  
  110. do {
  111. System.out.print("Enter state code: ");
  112. state = sc.next();
  113. } while (!state.matches("^[a-zA-Z\s]+"));
  114.  
  115. for (GISData datas : data) {
  116. if(datas.getStateCode().equals(state)) {
  117. foundData = datas;
  118. }
  119. }
  120. if(foundData != null)
  121. foundData.toString();
  122. else
  123. System.out.println("No data found.");
  124. }
  125.  
  126. public static void sort(ArrayList<GISData> data) {
  127. Collections.sort(
  128. data, (obj1, obj2) -> obj1.getElevationFeet() - obj2.getElevationFeet()
  129. );
  130. data.forEach(System.out::println);
  131.  
  132. }
  133.  
  134.  
  135. public static void edu(ArrayList<GISData> data) {
  136. GISData min1 = data.stream()
  137. .min(Comparator.comparingInt(GISData::getElevationFeet))
  138. .get();
  139. System.out.println("Area min elevation feet: " + min1);
  140.  
  141. GISData max1 = data.stream()
  142. .max(Comparator.comparingInt(GISData::getElevationFeet))
  143. .get();
  144. System.out.println("Area max elevation feet: " + max1);
  145. }
  146.  
  147. @Override
  148. public String toString() {
  149. StringBuilder retString = new StringBuilder();
  150. for (GISData gis : data) {
  151. retString.append(gis.toString());
  152. }
  153. return retString.toString();
  154. }
  155.  
  156. }
  157.  
  158. /**
  159. *
  160. */
  161. package edu.matc.itdev154.finalexam;
  162.  
  163. import java.util.Date;
  164.  
  165. public class GISData implements Comparable<GISData> {
  166. public static enum SortByType {CountyName,
  167. FeatureName,
  168. PrimaryLatitude,
  169. PrimaryLongitude,
  170. SourceLatitude,
  171. SourceLongitude,
  172. ElevationFeet};
  173.  
  174. private int featureId;
  175. private String featureName;
  176. private String featureClass;
  177. private String stateCode;
  178. private int stateId;
  179. private String countyName;
  180. private Integer countyId;
  181. private String primaryLatitudeDMS;
  182. private String primaryLongitudeDMS;
  183. private double primaryLatitudeDecimal;
  184. private double primaryLongitudeDecimal;
  185. private String sourceLatitudeDMS;
  186. private String sourceLongitudeDMS;
  187. private Double sourceLatitudeDecimal;
  188. private Double sourceLongitudeDecimal;
  189. private Integer elevationMeters;
  190. private Integer elevationFeet;
  191. private String mapName;
  192. private Date createdDate;
  193. private Date modifiedDate;
  194. private SortByType[] sortBy;
  195.  
  196. public GISData() {
  197.  
  198. }
  199. public GISData(int featureId, String featureName, String featureClass, String stateCode, int stateId,
  200. String countyName, Integer countyId, String primaryLatitudeDMS, String primaryLongitudeDMS,
  201. double primaryLatitudeDecimal, double primaryLongitudeDecimal, String sourceLatitudeDMS, String sourceLongitudeDMS, Double sourceLatitudeDecimal,
  202. Double sourceLongitudeDecimal, Integer elevationMeters, Integer elevationFeet, String mapName) {
  203. this.featureId = featureId;
  204. this.featureName = featureName;
  205. this.featureClass = featureClass;
  206. this.stateCode = stateCode;
  207. this.stateId = stateId;
  208. this.countyName = countyName;
  209. this.countyId = countyId;
  210. this.primaryLatitudeDMS = primaryLatitudeDMS;
  211. this.primaryLongitudeDMS = primaryLongitudeDMS;
  212. this.primaryLatitudeDecimal = primaryLatitudeDecimal;
  213. this.primaryLongitudeDecimal = primaryLongitudeDecimal;
  214. this.sourceLatitudeDMS = sourceLatitudeDMS;
  215. this.sourceLongitudeDMS = sourceLongitudeDMS;
  216. this.sourceLatitudeDecimal = sourceLatitudeDecimal;
  217. this.sourceLongitudeDecimal = sourceLongitudeDecimal;
  218. this.elevationMeters = elevationMeters;
  219. this.elevationFeet = elevationFeet;
  220. this.mapName = mapName;
  221. }
  222.  
  223. // Getters and Setters
  224.  
  225. @Override
  226. public int compareTo(GISData o) {
  227. return this.elevationFeet - o.elevationFeet;
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement