Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class elevAnalysis
- {
- public static void main (String[] args) throws FileNotFoundException
- {
- //Read in the values from a raw data set. Elevations will be of type double.
- Scanner elevDataFile = new Scanner(new File("rawElevData.txt"));
- ArrayList<Double> elevData = new ArrayList<Double>();
- while(elevDataFile.hasNextLine()){
- String line = elevDataFile.nextLine();
- Scanner scanner = new Scanner(line);
- scanner.useDelimiter(",");
- while(scanner.hasNextDouble()){
- elevData.add(scanner.nextDouble());
- }
- scanner.close();
- }
- elevDataFile.close();
- System.out.println(elevData); //First print is untouched data.
- //Run through array list and look for inaccurate changes. Read in tolerance.
- if (elevData.isEmpty())
- System.out.println("List is empty.");
- //Set up tolerance for comparing elevation values.
- Scanner keyboard = new Scanner(System.in);
- double tolerance = 50; //Tolerance can be changed.
- System.out.println("Tolerance is set at " + tolerance + ".\nPlease enter elevation tolerance.\n");
- tolerance = keyboard.nextInt();
- //Analyze elevation values looking for erratic/inaccurate changes.
- for (int i = 0; i < elevData.size(); ++i){
- double difference = Math.abs(elevData.get(i)-elevData.get(i+1));
- if(difference>tolerance){
- System.out.println("Value found out of tolerance.");
- elevData.set(i, elevData.get(i+1));
- }
- }
- //Print out new data and print to file.
- System.out.println("New data is as follows:\n");
- System.out.println(elevData);
- //Save arraylist to the cleanData file.
- PrintWriter pw = new PrintWriter(new FileOutputStream("cleanData.txt"));
- pw.println(elevData);
- pw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement