Advertisement
Guest User

elevAnalysis

a guest
Dec 5th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileOutputStream;
  4. import java.io.PrintWriter;
  5. import java.util.ArrayList;
  6. import java.util.Scanner;
  7.  
  8. public class elevAnalysis
  9. {
  10. public static void main (String[] args) throws FileNotFoundException
  11. {
  12. //Read in the values from a raw data set. Elevations will be of type double.
  13. Scanner elevDataFile = new Scanner(new File("rawElevData.txt"));
  14.  
  15. ArrayList<Double> elevData = new ArrayList<Double>();
  16.  
  17.  
  18. while(elevDataFile.hasNextLine()){
  19. String line = elevDataFile.nextLine();
  20.  
  21. Scanner scanner = new Scanner(line);
  22. scanner.useDelimiter(",");
  23. while(scanner.hasNextDouble()){
  24. elevData.add(scanner.nextDouble());
  25. }
  26. scanner.close();
  27. }
  28.  
  29. elevDataFile.close();
  30.  
  31. System.out.println(elevData); //First print is untouched data.
  32.  
  33. //Run through array list and look for inaccurate changes. Read in tolerance.
  34. if (elevData.isEmpty())
  35. System.out.println("List is empty.");
  36.  
  37.  
  38. //Set up tolerance for comparing elevation values.
  39. Scanner keyboard = new Scanner(System.in);
  40. double tolerance = 50; //Tolerance can be changed.
  41. System.out.println("Tolerance is set at " + tolerance + ".\nPlease enter elevation tolerance.\n");
  42. tolerance = keyboard.nextInt();
  43.  
  44. //Analyze elevation values looking for erratic/inaccurate changes.
  45. for (int i = 0; i < elevData.size(); ++i){
  46. double difference = Math.abs(elevData.get(i)-elevData.get(i+1));
  47. if(difference>tolerance){
  48. System.out.println("Value found out of tolerance.");
  49. elevData.set(i, elevData.get(i+1));
  50. }
  51. }
  52.  
  53. //Print out new data and print to file.
  54. System.out.println("New data is as follows:\n");
  55. System.out.println(elevData);
  56. //Save arraylist to the cleanData file.
  57. PrintWriter pw = new PrintWriter(new FileOutputStream("cleanData.txt"));
  58. pw.println(elevData);
  59. pw.close();
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement