Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Scanner;
- public class GISRunner {
- /**
- * @param args
- */
- public static void main(String[] args) throws FileNotFoundException {
- File file = new File("GIS.txt");
- Scanner input = new Scanner(file);
- String[] lineData = null;
- String lineRaw = null;
- String featureName, featureClass, stateCode, countyName, primaryLatitudeDMS, primaryLongitudeDMS,
- sourceLatitudeDMS, sourceLongitudeDMS, mapName;
- Integer featureId, stateId, countyId, elevationMeters, elevationFeet;
- Double primaryLatitudeDecimal, primaryLongitudeDecimal, sourceLatitudeDecimal, sourceLongitudeDecimal;
- GISDataStructure datas = new GISDataStructure();
- while (input.hasNext()) {
- lineRaw = input.nextLine();
- lineData = lineRaw.split("\|");
- featureId = 0;
- try {
- featureId = Integer.valueOf(lineData[0]);
- } catch (NumberFormatException e) {
- featureId = Integer.valueOf(lineData[0].substring(3));
- }
- featureName = lineData[1];
- featureClass = lineData[2];
- stateCode = lineData[3];
- stateId = Integer.valueOf(lineData[4]);
- countyName = lineData[5];
- try {
- countyId = Integer.valueOf(lineData[6]);
- } catch (NumberFormatException e2) {
- countyId = null;
- }
- primaryLatitudeDMS = lineData[7];
- primaryLongitudeDMS = lineData[8];
- primaryLatitudeDecimal = Double.valueOf(lineData[9]);
- primaryLongitudeDecimal = Double.valueOf(lineData[10]);
- sourceLatitudeDMS = lineData[11];
- sourceLongitudeDMS = lineData[12];
- try {
- sourceLatitudeDecimal = Double.valueOf(lineData[13]);
- } catch (NumberFormatException e1) {
- sourceLatitudeDecimal = null;
- }
- try {
- sourceLongitudeDecimal = Double.valueOf(lineData[14]);
- } catch (NumberFormatException e1) {
- sourceLongitudeDecimal = null;
- }
- try {
- elevationMeters = Integer.valueOf(lineData[15]);
- } catch (NumberFormatException e) {
- elevationMeters = null;
- }
- try {
- elevationFeet = Integer.valueOf(lineData[16]);
- } catch (NumberFormatException e) {
- elevationFeet = null;
- }
- mapName = lineData[17];
- GISData newGISData = new GISData(featureId, featureName, featureClass, stateCode, stateId, countyName,
- countyId, primaryLatitudeDMS, primaryLongitudeDMS, primaryLatitudeDecimal, primaryLongitudeDecimal,
- sourceLatitudeDMS, sourceLongitudeDMS, sourceLatitudeDecimal, sourceLongitudeDecimal,
- elevationMeters, elevationFeet, mapName);
- datas.insert(newGISData);
- }
- System.out.println(datas.toString());
- input.close();
- Collections.sort(datas);
- }
- }
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Scanner;
- import edu.matc.itdev154.finalexam.GISData.SortByType;
- public class GISDataStructure {
- private static Scanner sc = new Scanner(System.in);
- public ArrayList<GISData> data;
- public GISDataStructure() {
- data = new ArrayList<GISData>();
- }
- public void insert(GISData element) {
- data.add(element);
- }
- public static void searchData(ArrayList<GISData> data) {
- String state;
- GISData foundData = null;
- do {
- System.out.print("Enter state code: ");
- state = sc.next();
- } while (!state.matches("^[a-zA-Z\s]+"));
- for (GISData datas : data) {
- if(datas.getStateCode().equals(state)) {
- foundData = datas;
- }
- }
- if(foundData != null)
- foundData.toString();
- else
- System.out.println("No data found.");
- }
- public static void sort(ArrayList<GISData> data) {
- Collections.sort(
- data, (obj1, obj2) -> obj1.getElevationFeet() - obj2.getElevationFeet()
- );
- data.forEach(System.out::println);
- }
- public static void edu(ArrayList<GISData> data) {
- GISData min1 = data.stream()
- .min(Comparator.comparingInt(GISData::getElevationFeet))
- .get();
- System.out.println("Area min elevation feet: " + min1);
- GISData max1 = data.stream()
- .max(Comparator.comparingInt(GISData::getElevationFeet))
- .get();
- System.out.println("Area max elevation feet: " + max1);
- }
- @Override
- public String toString() {
- StringBuilder retString = new StringBuilder();
- for (GISData gis : data) {
- retString.append(gis.toString());
- }
- return retString.toString();
- }
- }
- /**
- *
- */
- package edu.matc.itdev154.finalexam;
- import java.util.Date;
- public class GISData implements Comparable<GISData> {
- public static enum SortByType {CountyName,
- FeatureName,
- PrimaryLatitude,
- PrimaryLongitude,
- SourceLatitude,
- SourceLongitude,
- ElevationFeet};
- private int featureId;
- private String featureName;
- private String featureClass;
- private String stateCode;
- private int stateId;
- private String countyName;
- private Integer countyId;
- private String primaryLatitudeDMS;
- private String primaryLongitudeDMS;
- private double primaryLatitudeDecimal;
- private double primaryLongitudeDecimal;
- private String sourceLatitudeDMS;
- private String sourceLongitudeDMS;
- private Double sourceLatitudeDecimal;
- private Double sourceLongitudeDecimal;
- private Integer elevationMeters;
- private Integer elevationFeet;
- private String mapName;
- private Date createdDate;
- private Date modifiedDate;
- private SortByType[] sortBy;
- public GISData() {
- }
- public GISData(int featureId, String featureName, String featureClass, String stateCode, int stateId,
- String countyName, Integer countyId, String primaryLatitudeDMS, String primaryLongitudeDMS,
- double primaryLatitudeDecimal, double primaryLongitudeDecimal, String sourceLatitudeDMS, String sourceLongitudeDMS, Double sourceLatitudeDecimal,
- Double sourceLongitudeDecimal, Integer elevationMeters, Integer elevationFeet, String mapName) {
- this.featureId = featureId;
- this.featureName = featureName;
- this.featureClass = featureClass;
- this.stateCode = stateCode;
- this.stateId = stateId;
- this.countyName = countyName;
- this.countyId = countyId;
- this.primaryLatitudeDMS = primaryLatitudeDMS;
- this.primaryLongitudeDMS = primaryLongitudeDMS;
- this.primaryLatitudeDecimal = primaryLatitudeDecimal;
- this.primaryLongitudeDecimal = primaryLongitudeDecimal;
- this.sourceLatitudeDMS = sourceLatitudeDMS;
- this.sourceLongitudeDMS = sourceLongitudeDMS;
- this.sourceLatitudeDecimal = sourceLatitudeDecimal;
- this.sourceLongitudeDecimal = sourceLongitudeDecimal;
- this.elevationMeters = elevationMeters;
- this.elevationFeet = elevationFeet;
- this.mapName = mapName;
- }
- // Getters and Setters
- @Override
- public int compareTo(GISData o) {
- return this.elevationFeet - o.elevationFeet;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement