package circulardata; /* This program contains the a class for the both circular data tests * and numerous methods to calculate them. * * Author: Ivan Ramler, Jake Krohn, and Brian Gluth * Date: 29 April 2002 */ import java.io.*; import java.util.*; public class CircularData { //fields private double[] data; //array of data private int observations; //number of obseravtions in data[] //default constructor public CircularData() { observations = 1; data = new double[observations]; data[0] = 0; } //Constructor for specific data public CircularData(File f) { try { FileReader fr = new FileReader(f); //create a new FileReader called fr BufferedReader br = new BufferedReader(fr); //create a new BufferedReader called br Vector inputValues = new Vector(); //data will be in a Vector called inputValues String input = ""; //read in file while (br.ready()) { input = br.readLine().trim(); //reads trimmed file until blank space is found then quits if (!input.equals("")) { Double inputValue = new Double(input); inputValues.add(inputValue); } else break; } observations = inputValues.size(); //sets observations to size of vector //check if observations is of legal size if (observations <= 1) { System.out.println("Not enough data to analyze. Program exiting."); System.exit(-1); } data = new double[observations]; //new array for data values //copies Vector inputValues to array data for (int i = 0; i < data.length; i++) { data[i] = ((Double) inputValues.get(i)).doubleValue(); } } catch (Exception e) { System.out.println("Exception: " + e + ". Program exiting"); System.exit(-1); } //check if all data is in the set of degrees [0,360) for (int k = 0; k < data.length; k++) { if (data[k] < 0.0 || data[k] >= 360.0) { System.out.println("Not all of data is in the set of degrees [0,360). Program exiting"); System.exit(-1); } } } //factorial method public static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); } //getData method public double[] getData() { return data; } //getObservations method public int getObservations() { return observations; } //selectionSort method public void selectionSort() { int i, j; //loop index int imin; //index of smallest value //sort values in ascending order for (i = 0; i < this.observations - 1; i++) { imin = i; //find min value in data[i] through data[this.observations - 1] for (j = i + 1; j < this.observations; j++) { if (data[j] < data[imin]) imin = j; } if (i != imin) //swap data[imin] and data[i] if i != imin { double temp = data[i]; data[i] = data[imin]; data[imin] = temp; } } } //setData method public void setData(double[] newData) { data = newData; } //setObservations method public void setObservations(int newObservations) { observations = newObservations; } }