Parcourir la source

Merge branch 'master' of https://github.com/tflucke/CPE103
merge branch into master
Conflicts:
.gitignore

Lara Luu il y a 10 ans
Parent
commit
31bf2f00c9

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.metadata
+.recommenders
+bin/

BIN
Lab3/bin/LQueue$MyException.class


BIN
Lab3/bin/LQueue$Node.class


BIN
Lab3/bin/LQueue.class


BIN
Lab3/bin/LQueueDriver.class


+ 4 - 6
Lab4/src/AStackClient.java

@@ -16,13 +16,13 @@ public class AStackClient {
 			AStack<String> strStack = new AStack<String>(n);
 			while (in.hasNext())
 			{
-				if (in.hasNextFloat())
+				if (in.hasNextInt())
 				{
-					fltStack.push(in.nextFloat());
+					intStack.push(in.nextInt());
 				}
-				else if (in.hasNextInt())
+				else if (in.hasNextFloat())
 				{
-					intStack.push(in.nextInt());
+					fltStack.push(in.nextFloat());
 				}
 				else
 				{
@@ -30,8 +30,6 @@ public class AStackClient {
 				}
 			}
 			in.close();
-			System.out.println("Abort mission");
-			
 			System.out.print("Strings:");
 			while (!strStack.isEmpty())
 			{

+ 6 - 0
Lab5/.classpath

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Lab5/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Lab5</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 12 - 0
Lab5/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+#Mon Oct 05 11:08:17 PDT 2015
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

+ 82 - 0
Lab5/src/AQueue.java

@@ -0,0 +1,82 @@
+
+public class AQueue <T>
+{
+	private T[] arr;
+	private int front;
+	private int end;
+	private int count;
+	
+	public static class MyException extends RuntimeException
+	{
+		private static final long serialVersionUID = -244806549310243756L;
+		public MyException()
+		{
+			super();
+		}
+		public MyException(String message)
+		{
+			super(message);
+		}
+	}
+	
+	public AQueue(int arrSize)
+	{
+		arr = (T[]) new Object[arrSize];
+		front = 0;
+		end = -1;
+		count = 0;
+	}
+	
+	public boolean isEmpty()
+	{
+		return (count < 1);
+	}
+	
+	public void enqueue(T item)
+	{
+		if(count == arr.length)
+		{
+			T[] tmpArr = (T[]) new Object[arr.length * 2];
+			for (int i = 0; i < count; i++)
+			{
+				tmpArr[i] = arr[(front + i) % arr.length];
+				
+			}
+			arr = tmpArr;
+			front = 0;
+			end = count - 1;
+		}
+		end = (end + 1) % arr.length;
+		arr[end] = item;
+		count ++;
+	}
+	
+	public T dequeue()
+	{
+		if (isEmpty())
+		{
+			throw new MyException();
+		}
+		T tmp = arr[front];
+		arr[front] = null;
+		front = (front + 1) % arr.length;
+		count --;
+		return tmp;
+	}
+	
+	public void printArray()
+	{
+		for (int i = 0; i < arr.length; i++)
+		{
+			System.out.print(arr[i] + " ");
+		}
+		
+		System.out.println();
+	}
+	
+	
+	
+	
+	
+	
+}

+ 30 - 0
Lab5/src/AQueueClient.java

@@ -0,0 +1,30 @@
+import java.util.Scanner;
+
+public class AQueueClient 
+{
+	public static void main(String[] args)
+	{
+		Scanner input = new Scanner(System.in);
+		AQueue<Float> floatArr =  new AQueue<Float>(5);
+
+		while(input.hasNext())
+		{
+			if(input.hasNextFloat())
+			{
+				floatArr.enqueue(input.nextFloat());
+			}
+			else
+			{
+				input.next();
+			}
+		}
+		
+		while (!floatArr.isEmpty())
+		{
+			System.out.print(floatArr.dequeue() + " ");
+		}
+		
+		System.out.println();
+		
+	}
+}

+ 77 - 0
Lab5/src/AQueueDriver.java

@@ -0,0 +1,77 @@
+import java.util.Scanner;
+
+public class AQueueDriver {
+	public static void main(String[] args) {
+		Scanner in = new Scanner(System.in);
+		AQueue<Integer> queue = new AQueue<Integer>(5);
+		printHelp();
+		boolean running = true;
+		while (running)
+		{   System.out.println("Enter a menu choice: ");
+			String line = in.nextLine();
+			if (line.length() != 1)
+			{
+				System.out.println("Invalid Option.");
+				//printHelp();
+				continue;
+			}
+			char command = line.charAt(0);
+			switch (command)
+			{
+				case 'a':
+					System.out.println("Enter an integer.");
+					if (in.hasNextInt())
+					{
+						int newVal = in.nextInt();
+						queue.enqueue(newVal);
+						System.out.println(newVal+" enqueued");
+					}
+					else
+					{
+						System.out.println("Not an integer.  No action taken.");
+					}
+					in.nextLine();
+					break;
+				case 'd':
+					try
+					{
+						System.out.println(queue.dequeue() +" dequeued");
+					}
+					catch (AQueue.MyException me)
+					{
+						System.out.println("Invalid operation.  Queue is empty.");
+					}
+					break;
+				case 'e':
+					System.out.println(queue.isEmpty()? "Empty":"Not Empty");
+					break;
+				case 'p':
+					queue.printArray();
+					break;
+				case 'q':
+					running = false;
+					System.out.println("Quitting");
+					break;
+				default:
+					System.out.println("Invalid Option.");
+					//printHelp();
+			}
+		}
+		while (!queue.isEmpty())
+		{
+			System.out.print(queue.dequeue()+" ");
+		}
+		System.out.println();
+	}
+	
+	public static void printHelp()
+	{
+		System.out.println("Options:");
+		System.out.println("\"a\" -\tAdd to Queue");
+		System.out.println("\"d\" -\tRemove from Queue");
+		System.out.println("\"e\" -\tCheck if Queue is empty");
+		System.out.println("\"p\" -\tPrint");
+		System.out.println("\"q\" -\tQuit");
+	}
+
+}

+ 6 - 0
Lab6/.classpath

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Lab6/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Lab6</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 12 - 0
Lab6/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+#Wed Oct 07 11:29:47 PDT 2015
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

+ 61 - 0
Lab6/src/AStack.java

@@ -0,0 +1,61 @@
+public class AStack<T> {
+	public static class MyException extends RuntimeException
+	{
+		private static final long serialVersionUID = -244806549310243756L;
+		public MyException()
+		{
+			super();
+		}
+		public MyException(String message)
+		{
+			super(message);
+		}
+	}
+	
+	private T[] arr;
+	private int top;
+
+	@SuppressWarnings("unchecked")
+	public AStack(int size)
+	{
+		arr = (T[]) new Object[size];
+		top = -1;
+	}
+
+	@SuppressWarnings("unchecked")
+	public void push(T item)
+	{
+		if (top+1 == arr.length)
+		{
+			T[] newArr = (T[]) new Object[2*arr.length];
+			for (int i = 0; i <= top; i++)
+			{
+				newArr[i] = arr[i];
+			}
+			arr = newArr;
+		}
+		arr[++top] = item;
+	}
+
+	public T pop()
+	{
+		if (isEmpty())
+		{
+			throw new MyException();
+		}
+		return arr[top--];
+	}
+	public T peek()
+	{
+		if (isEmpty())
+		{
+			throw new MyException();
+		}
+		return arr[top];
+	}
+	
+	public boolean isEmpty()
+	{
+		return top < 0;
+	}
+}

+ 63 - 0
Lab6/src/StringChecker.java

@@ -0,0 +1,63 @@
+import java.util.Scanner;
+
+
+
+public class StringChecker 
+{
+
+	public static boolean isBalanced(String input)
+	{
+		AStack<Character> charStack = new AStack<Character>(5);
+		try
+		{
+			for (int i = 0; i < input.length(); i++)
+			{
+				char c = input.charAt(i);
+				
+				switch(c)
+				{
+					case '{':
+					case '(':
+					case '[':
+						charStack.push(c);
+						break;
+					case '}':
+						if (charStack.pop() != '{')
+						{
+							return false;
+						}
+						break;
+					case ')':
+						if (charStack.pop() != '(')
+						{
+							return false;
+						}
+						break;
+					case ']':
+						if (charStack.pop() != '[')
+						{
+							return false;
+						}
+						break;
+				}
+			}
+		}
+		catch (AStack.MyException me)
+		{
+			return false;
+		}
+		return charStack.isEmpty();
+	}
+	
+	public static void main(String[] args)
+	{
+		System.out.println("Hey baby. Can you please give me a string to check? :)");
+		Scanner in = new Scanner(System.in);
+		while(in.hasNextLine())
+		{
+			System.out.println(isBalanced(in.nextLine())? "Congrats, your string is indeed balanced (:" : 
+														  "I'm sorry, but you suck at balancing strings ):");
+		}
+		
+	}
+}

+ 6 - 0
Lab7/.classpath

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Lab7/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Lab7</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 12 - 0
Lab7/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+#Mon Oct 12 11:08:10 PDT 2015
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

+ 28 - 0
Lab7/src/TreeTest.java

@@ -0,0 +1,28 @@
+import java.util.Scanner;
+
+
+public class TreeTest
+{
+	public static void main(String... args)
+	{
+		Integer[] arr = new Integer[20];
+		int size = 0;
+		Scanner in = new Scanner(System.in);
+		System.out.println("Waddup boosh. I herd you like giving me a tree to input. (:");
+		while (size != arr.length && in.hasNextInt())
+		{
+			arr[size++] = in.nextInt();
+		}
+		in.close();
+		if (size == 0)
+		{
+			System.out.println("The tree is empty.");
+		}
+		else
+		{
+			System.out.println(TreeWork.isHeap(arr, size)? "Is Heap":"Is Not Heap");
+			System.out.println();
+			TreeWork.printTree(arr, size);
+		}
+	}
+}

+ 64 - 0
Lab7/src/TreeWork.java

@@ -0,0 +1,64 @@
+
+public class TreeWork
+{
+	private static int leftChild(int index)
+	{
+		return 2*index+1;
+	}
+	private static int rightChild(int index)
+	{
+		return 2*index+2;
+	}
+	
+	public static<T extends Comparable<? super T>> boolean isHeap(T[] tree, int size)
+	{
+		return isHeap(tree, 0, size);
+	}
+	
+	private static<T extends Comparable<? super T>> boolean isHeap(T[] tree, int start, int size)
+	{
+		if (leftChild(start) >= size)
+		{
+			return true;
+		}
+		else if (tree[leftChild(start)].compareTo(tree[start]) < 0)
+		{
+			return false;
+		}
+		else if (!isHeap(tree, leftChild(start), size))
+		{
+			return false;
+		}
+		
+		else if (rightChild(start) >= size)
+		{
+			return true;
+		}
+		else if (tree[rightChild(start)].compareTo(tree[start]) < 0)
+		{
+			return false;
+		}
+		else if (!isHeap(tree, rightChild(start), size))
+		{
+			return false;
+		}
+		
+		else
+		{
+			return true;
+		}
+	}
+	
+	public static<T> void printTree(T[] tree, int size)
+	{
+		for (int i = 0; i < size; i++)
+		{
+			if (i != 0 && (Math.log(i + 1)/Math.log(2)) % 1 == 0)
+			{
+				System.out.println();
+			}
+			System.out.print(tree[i] + " ");
+		}
+		System.out.println();
+	}
+}

+ 6 - 0
Project1/.classpath

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Project1/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Project1</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 11 - 0
Project1/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

+ 68 - 0
Project1/src/ConTest.java

@@ -0,0 +1,68 @@
+/**
+ * Driver program to allow command line user to interface with the Converter methods.
+ * 
+ * Project 1
+ * 
+ * @author Thomas Flucke tflucke
+ * @author Lara Luu ljluu
+ * 
+ * @since 2015/10/07
+ * 
+ * @see Converter
+ */
+import java.util.EmptyStackException;
+import java.util.Scanner;
+
+public class ConTest
+{
+	/**
+	 * Runs the program.
+	 */
+	public static void main(String... args)
+	{
+		Scanner in = new Scanner(System.in); // class to read from the console
+		System.out.println("Choose one of the following operations:");
+		System.out.println("- Infix to postfix conversion (enter the letter i)");
+		//We removed the "," from p because none of the other options had it.
+		System.out.println("- Postfix expression evaluation (enter the letter p)");
+		System.out.println("- Arithmetic expression evaluation (enter the letter a)");
+		System.out.println("- Quit the program (enter the letter q)");
+		System.out.println("Please insert a menu choice.");
+		String line; // variable to store the read input by line
+		while (!(line = in.nextLine()).equals("q"))
+		{
+			if (line.length() != 1)
+			{
+				System.out.println("Invalid choice");
+			}
+			char option = line.charAt(0); // stores option to be read in switch statement 
+			try
+			{
+				switch (option)
+				{
+				case 'i':
+					System.out.println("Please enter the infix expression to be converted to postfix: ");
+					System.out.println("the postfix expression is: "+Converter.infixToPostfix(in.nextLine()));
+					break;
+				case 'p':
+					System.out.println("Please enter the postfix expression to be evaluated: ");
+					System.out.println("the value of the postfix expression is: "+Converter.postfixValue(in.nextLine()));
+					break;
+				case 'a':
+					System.out.println("Please enter the arithmetic expression to be evaluated: ");
+					System.out.println("the value of the arithmetic expression is: "+Converter.postfixValue(Converter.infixToPostfix(in.nextLine())));
+					break;
+				default:
+					System.out.println("Invalid choice");
+				}
+			}
+			catch (EmptyStackException ese)
+			{
+				System.out.println("Invalid operation on an empty stack");	
+			}
+			System.out.println("Please insert a menu choice.");
+		}
+		System.out.println("quitting");
+		in.close();
+	}
+}

+ 101 - 0
Project1/src/Converter.java

@@ -0,0 +1,101 @@
+/**
+ * A class containing methods for manipulating postfix expressions.
+ * 
+ * Project 1
+ * 
+ * @author Thomas Flucke tflucke
+ * @author Lara Luu ljluu
+ * 
+ * @since 2015/10/07
+ */
+import java.util.Scanner;
+
+public class Converter
+{
+	/**
+	 * Converts an infix expression to postfix notation
+	 * @return The postfix expression as a space separated character string
+	 */
+	public static String infixToPostfix (String expression)
+	{
+		MyStack<Character> operatorStack = new MyStack<Character>(); // Creates stack in which to store operators
+		Scanner in = new Scanner(expression); // class to read from console
+		String output = new String(); // creates string to be used as output
+		while (in.hasNext())
+		{
+			String num = in.next(); // used to print the number if it is not an operator
+			char operator = num.charAt(0); // switchable operator
+			if (operator == '+' || operator == '-' || operator == '(')
+			{
+				operatorStack.push(operator);
+			}
+			else if (operator == '*' || operator == '/')
+			{
+				char nextOperator = operatorStack.peek();
+				while (!(nextOperator == '+' || nextOperator == '-' || nextOperator == '('))
+				{
+					output += operatorStack.pop() + " ";
+				}
+				operatorStack.push(operator);
+			}
+			else if (operator == ')')
+			{
+				while (operatorStack.peek() != '(')
+				{
+					output += operatorStack.pop() + " ";
+				}
+				operatorStack.pop();
+			}
+			else
+			{
+				output += num + " ";	
+			}
+		}
+		in.close();
+		while (!operatorStack.isEmpty())
+		{
+			output += operatorStack.pop() + " ";
+		}
+		return output.trim();
+	}
+
+	/**
+	 * Evaluates a postfix expression into a double value.
+	 * @return The double value derived from the postfix expression
+	 */
+	public static double postfixValue (String expression)
+	{
+		MyStack<Double> valueStack = new MyStack<Double>(); // create a stack in which to load doubles to be evaluated
+		Scanner in = new Scanner(expression); // class to read from console
+		while (in.hasNext())
+		{
+			if (in.hasNextDouble())
+			{
+				valueStack.push(in.nextDouble());
+			}
+			else
+			{
+				double tmp; // used for order-sensitive operations ( "-" & "/")
+				switch (in.next().charAt(0))
+				{
+					case '+':
+						valueStack.push(valueStack.pop() + valueStack.pop());
+						break;
+					case '-':
+						tmp = valueStack.pop();
+						valueStack.push(valueStack.pop() - tmp);
+						break;
+					case '*':
+						valueStack.push(valueStack.pop() * valueStack.pop());
+						break;
+					case '/':
+						tmp = valueStack.pop();
+						valueStack.push(valueStack.pop() / tmp);
+						break;
+				}
+			}
+		}
+		in.close();
+		return valueStack.pop();
+	}
+}

+ 83 - 0
Project1/src/MyStack.java

@@ -0,0 +1,83 @@
+/**
+ * Linked list implementation of a stack.
+ * 
+ * Project 1
+ * 
+ * @author Thomas Flucke tflucke
+ * @author Lara Luu ljluu
+ * 
+ * @since 2015/10/07
+ */
+
+import java.util.EmptyStackException;
+public class MyStack<T>
+{
+	/**
+	 * A single node containing an item in the list and a reference to the next node.
+	 */
+	private class Node
+	{
+		public T elm; // contains the data in the node
+		
+		public Node next; // contains the location of the next linked node
+	}
+	
+	private Node first; // contains the first node in the linked list
+	
+	/**
+	 * Initializes an instance of MyStack
+	 */
+	public MyStack()
+	{
+		first = null;
+	}
+	
+	/**
+	 * Places an item at the front of the stack.
+	 * @param item The item to be placed on the stack.
+	 */
+	public void push(T item)
+	{
+		Node newFirst = new Node(); // creates a new node
+		newFirst.elm = item; 
+		newFirst.next = first; 
+		first = newFirst; 
+	}
+
+	/**
+	 * Removes an item from the front of the stack.
+	 * @return The item removed from the stack.
+	 */
+	public T pop()
+	{
+		if (isEmpty())
+		{
+			throw new EmptyStackException();
+		}
+		T val = first.elm; // stores object to be returned
+		first = first.next;
+		return val;
+	}
+	
+	/**
+	 * Returns the value at the front of the stack.
+	 * @return The item at the front of the stack.
+	 */
+	public T peek()
+	{
+		if (isEmpty())
+		{
+			throw new EmptyStackException();
+		}
+		return first.elm;
+	}
+	
+	/**
+	 * Checks if there are any items left on the stack.
+	 * @return true if there are no items on the stack, false otherwise.
+	 */
+	public boolean isEmpty()
+	{
+		return first == null;
+	}
+}

+ 71 - 0
Project1/src/StackTest.java

@@ -0,0 +1,71 @@
+/**
+ * Driver program to allow command line user to interface with a MyStack instance.
+ * 
+ * Project 1
+ * 
+ * @author Thomas Flucke tflucke
+ * @author Lara Luu ljluu
+ * 
+ * @since 2015/10/07
+ * 
+ * @see MyStack
+ */
+import java.util.EmptyStackException;
+import java.util.Scanner;
+
+public class StackTest
+{
+	/**
+	 * Runs the program.
+	 */
+	public static void main(String... args)
+	{
+		Scanner in = new Scanner(System.in); // class to read from console
+		MyStack<String> stack = new MyStack<String>(); // initializes stack to manipulate inputs onto
+		System.out.println("Choose one of the following operations:");
+		System.out.println("- push/add (enter the letter a)");
+		System.out.println("- pop/delete (enter the letter d)");
+		System.out.println("- peek (enter the letter p)");
+		System.out.println("- check if the list is empty (enter the letter e)");
+		System.out.println("- Quit (enter the letter q)");
+		String line; // variable to store the read input by line
+		System.out.println("Please insert a menu choice.");
+		while (!(line = in.nextLine()).equals("q"))
+		{
+			if (line.length() != 1)
+			{
+				System.out.println("Invalid choice");
+			}
+			char option = line.charAt(0);; // stores option to be read in switch statement 
+			try
+			{
+				switch (option)
+				{
+				case 'a':
+					String pushed = in.nextLine(); // saves next input to be pushed onto the stack
+					stack.push(pushed);
+					System.out.println(pushed+" pushed in");
+					break;
+				case 'd':
+					System.out.println(stack.pop()+" popped out");
+					break;
+				case 'p':
+					System.out.println(stack.peek()+" on the top");
+					break;
+				case 'e':
+					System.out.println(stack.isEmpty()? "empty":"not empty");
+					break;
+					default:
+						System.out.println("Invalid choice");
+				}
+			}
+			catch (EmptyStackException ese)
+			{
+				System.out.println("Invalid operation on an empty stack");	
+			}
+			System.out.println("Please insert a menu choice.");
+		}
+		System.out.println("quitting");
+		in.close();
+	}
+}