diff --git a/ArrayStack.java b/ArrayStack.java new file mode 100644 index 0000000..bc82657 --- /dev/null +++ b/ArrayStack.java @@ -0,0 +1,65 @@ +import java.util.EmptyStackException; + +public class ArrayStack implements BKStack +{ + double[] Stack; + int pointer; + + public ArrayStack() //default with initial size of 10 + { + Stack = new double[10]; + pointer = 0; + } + + public ArrayStack(int size) //manual initializer of custom size + { + Stack = new double[size]; + pointer = 0; + } + + public void push(double insert) + { + if(pointer == Stack.length) + resize(); + + Stack[pointer] = insert; + pointer++; + } + + public void resize() + { + double[] middleMan = Stack.clone(); + Stack = new double[Stack.length *2]; //twice original size + + for(int i = 0; i < middleMan.length; i++) + Stack[i] = middleMan[i]; + } + + public double pop() + { + if(!isEmpty()) + { + pointer--; + return Stack[pointer]; + } + else + { + System.out.println("ERROR, poping empty ArrayStack"); //EmptyStackException; I realize I could use a Try/Catch, but I think the if's look better here. + System.exit(1); + return -1; + } + } + + public double peek() + { + return Stack[pointer -1]; + } + + public boolean isEmpty() + { + if(pointer > 0) + return false; + else + return true; + } +} diff --git a/ArrayStackIterable.java b/ArrayStackIterable.java new file mode 100644 index 0000000..3277f90 --- /dev/null +++ b/ArrayStackIterable.java @@ -0,0 +1,71 @@ +import java.util.Arrays; +import java.util.EmptyStackException; +import java.util.Iterator; + + +public class ArrayStackIterable implements Iterable +{ + Double[] Stack; + int pointer; + + public ArrayStackIterable() //default with initial size of 10 + { + Stack = new Double[10]; + pointer = 0; + } + + public void push(double insert) + { + if(pointer == Stack.length) + resize(); + + Stack[pointer] = (Double)(insert); + pointer++; + } + + public void resize() + { + Double[] middleMan = Stack.clone(); + Stack = new Double[Stack.length *2]; //twice original size + + for(int i = 0; i < middleMan.length; i++) + Stack[i] = middleMan[i]; + } + + public double pop() + { + Iterator I = iterator(); + + if(!I.hasNext()) + { + pointer--; + return (double)(Stack[pointer]); + } + else + { + System.out.println("ERROR, poping empty ArrayStack"); //EmptyStackException; i realise i could use a try/catch here, but i think this makes more sense. + System.exit(1); + return -1; + } + } + + public double peek() + { + return Stack[pointer -1]; + } + + public boolean isEmpty() + { + if(pointer > 0) + return false; + else + return true; + } + + @Override + public Iterator iterator() + { + Iterator I = Arrays.stream(Stack).iterator(); + return I; + } +} diff --git a/BKStack.java b/BKStack.java new file mode 100644 index 0000000..c0bba1a --- /dev/null +++ b/BKStack.java @@ -0,0 +1,35 @@ +/** + * Interface for a stack of primitive doubles. + * + * NOTE: You will need to provide much better descriptive + * comments than the ones provided in this interface + */ +public interface BKStack { + + /** + * is empty? + */ + public boolean isEmpty(); + + /** + * push + */ + public void push(double d); + + /** + * pop + * + * @return the deleted value + * @throws EmptyStackException if stack is empty + * + */ + public double pop(); + + /** + * peek + * + * @throws EmptyStackException f stack is empty + * i + */ + public double peek(); +} \ No newline at end of file diff --git a/BackMasking.java b/BackMasking.java new file mode 100644 index 0000000..7bea75e --- /dev/null +++ b/BackMasking.java @@ -0,0 +1,143 @@ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +/** + * Read a .dat file and reverse it. + * + * couresy of Milne @UWashington + */ +public class BackMasking{ + + //@SuppressWarnings("unused") + public static void main(String[] args) + { + + if (args.length != 3) + { + System.err.println(" Incorrect number of arguments"); + System.err.println(" Usage: "); + System.err.println("\tjava BackMasking "); + System.exit(1); + } + + boolean useList = true; + if (args[0].compareTo("list") == 0) + useList = true; + else if (args[0].compareTo("array") == 0) + useList = false; + else + { + System.err.println("\tsaw " + args[0] + " instead of list or array as first argument"); + System.exit(1); + } + + try { + // + // Set up the input file to read, and the output file to write to + // + BufferedReader fileIn = new BufferedReader(new FileReader(args[1])); + PrintWriter fileOut = new PrintWriter(new BufferedWriter(new FileWriter(args[2]))); + + // + // Read the first line of the .dat file to get sample rate. + // We want to store the sample rate value in a variable, + // but we can ignore the "; Sample Rate" part of the line. + // Step through the first line one token (word) at a time + // using the StringTokenizer. The fourth token is the one + // we want (the sample rate). + // + StringTokenizer str; + String oneLine; + int sampleRate; + String strJunk; + + oneLine = fileIn.readLine(); + + str = new StringTokenizer(oneLine); + strJunk = str.nextToken(); // Read in semicolon + strJunk = str.nextToken(); // Read in "Sample" + strJunk = str.nextToken(); // Read in "Rate" + + // Read in sample rate + sampleRate = Integer.parseInt(str.nextToken()); + + // + // Read in the remainder of the file on line at a time. + // The values in the first column are thrown away. + // Place values from the second column on the stack. + // Stop reading if we reach the end of the file. + // + + BKStack s; + if (useList) + s = new ListStack(); + else + s = new ArrayStack(); + String timestep; + double data; + + int count = 0; + while ((oneLine = fileIn.readLine()) != null) + { + if (oneLine.charAt(0) == ';') + { + continue; + } + str = new StringTokenizer(oneLine); + + // Read in time step value from first column + timestep = str.nextToken(); + // Read in data value from second column + data = Double.parseDouble(str.nextToken()); + s.push(data); + count++; + } + + System.out.println(count + " samples in file"); + + // + // Print the data values to output .dat file. + // First, output the header line: + // "; Sample Rate " + // + fileOut.println("; Sample Rate " + sampleRate); + + // Since the first column consists of numbers which start + // at 0 and increase by 1/sampleRate every time slice, we'll + // just use numSteps to recalculate these numbers. + int numSteps = 0; + + // Finally, we print the values in reverse order (by popping + // them off the stack). The first column consists of numbers + // which start at 0 and increase by 1/sampleRate per row, so + // we'll use numSteps/sampleRate to recalculate the appropriate + // values. Print a tab for uniform spacing. + + while (!s.isEmpty()) + { + fileOut.println((double) numSteps / sampleRate + "\t" + s.pop()); + numSteps++; + } + + // + // Close the files + // + fileIn.close(); + fileOut.close(); + + } catch (IOException ioe) { + System.err + .println("Error opening/reading/writing input or output file."); + System.exit(1); + } catch (NumberFormatException nfe) { + System.err.println(nfe.toString()); + System.err.println("Error in file format"); + System.exit(1); + } + } +} \ No newline at end of file diff --git a/ListStack.java b/ListStack.java new file mode 100644 index 0000000..7eca678 --- /dev/null +++ b/ListStack.java @@ -0,0 +1,48 @@ +import java.util.EmptyStackException; + +public class ListStack implements BKStack +{ + ListStackNode root; + + public ListStack() + { + root = new ListStackNode(-1, null); //dummy values for a end-of-line node + } + + public void push(double input) + { + ListStackNode prev = root; + root = new ListStackNode(input, prev); + } + + public double pop() + { + if(root.next != null) + { + double returner = root.data; + root = root.next; + return returner; + } + else + { + System.err.println("EmptyStackException"); + return -1; + } + } + + public double peek() + { + if(!isEmpty()) + return root.data; + else + return -1; + } + + public boolean isEmpty() + { + if(root.next == null) + return true; + else + return false; + } +} diff --git a/ListStackIterable.java b/ListStackIterable.java new file mode 100644 index 0000000..941a727 --- /dev/null +++ b/ListStackIterable.java @@ -0,0 +1,56 @@ +import java.util.Iterator; +import java.util.List; + +public class ListStackIterable implements Iterable +{ + ListStackNode root; + + public ListStackIterable() + { + root = new ListStackNode(-1, null); //dummy values for a end-of-line node + } + + public void push(double input) + { + ListStackNode prev = root; + root = new ListStackNode(input, prev); + } + + public double pop() + { + if(root.next != null) + { + double returner = root.data; + root = root.next; + return returner; + } + else + { + System.err.println("EmptyStackException"); + return -1; + } + } + + public double peek() + { + if(!isEmpty()) + return root.data; + else + return -1; + } + + public boolean isEmpty() + { + if(root.next == null) + return true; + else + return false; + } + + @Override + public Iterator iterator() + { + Iterator I = null; + return I; + } +} diff --git a/ListStackNode.java b/ListStackNode.java new file mode 100644 index 0000000..637df76 --- /dev/null +++ b/ListStackNode.java @@ -0,0 +1,11 @@ +public class ListStackNode +{ + double data; + ListStackNode next; + + public ListStackNode(double input, ListStackNode prev) + { + this.data = input; + this.next = prev; + } +} diff --git a/ReadMe.pdf b/ReadMe.pdf new file mode 100644 index 0000000..c9a2aff Binary files /dev/null and b/ReadMe.pdf differ diff --git a/Tester.java b/Tester.java new file mode 100644 index 0000000..2a8bbdf --- /dev/null +++ b/Tester.java @@ -0,0 +1,24 @@ +import java.util.List; + +public class Tester +{ + public static void main(String[] args) + { + //System.out.println("It Works!"); + + /*ArrayStack S = new ArrayStack(); + S.push(1.2); + S.push(2.5); + //System.out.println(S.pop() + " " + S.peek()); + S.push(3.14); + System.out.println(S.pop() + " " + S.pop() + " " + S.pop()); + */ + + ListStack S = new ListStack(); + S.push(1.2); + S.push(2.5); + System.out.println(S.peek()); + S.push(3.14); + System.out.println(S.pop() + " " + S.pop() + " " + S.pop()); + } +} diff --git a/ciphered.wav b/ciphered.wav new file mode 100644 index 0000000..8fb75be Binary files /dev/null and b/ciphered.wav differ diff --git a/clip.wav b/clip.wav new file mode 100644 index 0000000..72ccd11 Binary files /dev/null and b/clip.wav differ