diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 32858aa..0000000 --- a/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/production/.DS_Store b/production/.DS_Store new file mode 100644 index 0000000..ef09981 Binary files /dev/null and b/production/.DS_Store differ diff --git a/production/ClassProject/.DS_Store b/production/ClassProject/.DS_Store new file mode 100644 index 0000000..0bd3302 Binary files /dev/null and b/production/ClassProject/.DS_Store differ diff --git a/production/ClassProject/ClassProject.java b/production/ClassProject/ClassProject.java new file mode 100644 index 0000000..6fefa6b --- /dev/null +++ b/production/ClassProject/ClassProject.java @@ -0,0 +1,20 @@ +package edu.oakland.production.ClassProject; + +import edu.oakland.production.ClassProject.Display.Display; + +/** + * CSE 231 -- Class Project main class. + * This class will instantiate a Display object, and the whole program + * will run from there. + * @author Evan Bradley + * @version 1.0 + * @since 2015-04-01 + */ + +public class ClassProject { + + public static void main(String[] args) { + Display display = new Display(); + display.mainMenu(); + } +} diff --git a/production/ClassProject/Database/.DS_Store b/production/ClassProject/Database/.DS_Store new file mode 100644 index 0000000..c96d7af Binary files /dev/null and b/production/ClassProject/Database/.DS_Store differ diff --git a/production/ClassProject/Database/ArrayListDatabase.java b/production/ClassProject/Database/ArrayListDatabase.java new file mode 100644 index 0000000..d37c6f9 --- /dev/null +++ b/production/ClassProject/Database/ArrayListDatabase.java @@ -0,0 +1,62 @@ +package edu.oakland.production.ClassProject.Database; +import java.util.*; + +/** +* This is a class for ArrayList +*Fill the following Data Structures with Random Numbers from 100 to 1000 Each Data St +*ructure shall have (1) 100K elements; (2) 200K elements; (3) 400K elements; +*1.Create an ArrayList +*@author "Arpan Rughani and Bryan Purakal" +*@version "version 1.1" +*@since "152503" +*/ +public class ArrayListDatabase{ + + /** Declare arraylist + */ + private ArrayList students; + + /**Overloaded constructor to create ArrayList object of size "size" + */ + ArrayListDatabase(int size){ + students = new ArrayList(size); + } + + /**Get Student Method + * + * @param index of student from array + * @return student from selected index + */ + public Integer getStudent(int i){ + return students.get(i); + } + + /**set Student Method + * @param index of student from array + */ + public void setStudent(int i, int j){ + students.add(i,j); + } + + /**Add student method + */ + public void addStudent(int i){ + students.add(i); + } + + /**remove Student Method + * @param index of student from array + */ + public void removeStudent(int i){ + students.remove(i); + } + + + public int returnSize(){ + return students.size(); + } + + public void clearAllStudents(){ + students.clear(); + } +} diff --git a/production/ClassProject/Database/BinaryTreeDB.java b/production/ClassProject/Database/BinaryTreeDB.java new file mode 100644 index 0000000..10d8d7b --- /dev/null +++ b/production/ClassProject/Database/BinaryTreeDB.java @@ -0,0 +1,257 @@ +package edu.oakland.production.ClassProject.Database; + +/** +*@author Bryan J. and David M. +*@version version 2.0 150324 +*@since version 1.0 +*/ + +public class BinaryTreeDB { + + Node root; + +/** +*The addNode method adds a node to the binary tree +*@param key The integer being added/stored withing the binaryTree +*@param name The name of the node being added/stored +*/ + public void addNode(int key, T name) { + + Node newNode = new Node(key, name); + + if(root == null){ + + root = newNode; + }else { + + Node focusNode = root; + + Node parent; + + while(true){ + + parent = focusNode; + + if(key < focusNode.key){ + + focusNode = focusNode.leftChild; + + if(focusNode == null){ + + parent.leftChild = newNode; + return; + } + }else { + focusNode = focusNode.rightChild; + + if(focusNode == null){ + parent.rightChild = newNode; + return; + + } + } + } + } + } + + +/** +*The inOrderTraverseTree method uses an In-Order search and prints out the value of each node as it traverses +*@param focusNode The node that you want to begin your search at +*/ + public void inOrderTraverseTree(Node focusNode) { + + if( focusNode != null){ + + inOrderTraverseTree(focusNode.leftChild); + + System.out.println(focusNode); + + inOrderTraverseTree(focusNode.rightChild); + } + } +/** +*The preorderTraverseTree method uses an Pre-Order search and prints out the value of each node as it traverses +*@param focusNode The node that you want to begin your search at +*/ + public void preorderTraverseTree(Node focusNode) { + + if( focusNode != null){ + + System.out.println(focusNode); + + preorderTraverseTree(focusNode.leftChild); + + preorderTraverseTree(focusNode.rightChild); + } + } + +/** +*The findNode method finds a node containing the specified key value +*@param key The int value you want to find +*@return The node containing the specified int value +*/ + public Node findNode(int key){ + + Node focusNode = root; + + while(focusNode.key != key){ + + if(key < focusNode.key){ + + focusNode = focusNode.leftChild; + }else { + + focusNode = focusNode.rightChild; + } + + if (focusNode == null) + return null; + } + + return focusNode; + } + +/** +*The remove method removes a node from the tree +*@param key The integer you want to remove +*@return A boolean representing whether the node was removed or not, true for yes, false for no +*/ + public boolean remove(int key){ + + Node focusNode = root; + Node parent = root; + + boolean isItALeftChild = true; + + while(focusNode.key != key){ + + parent = focusNode; + + if(key < focusNode.key){ + + isItALeftChild = true; + + focusNode = focusNode.leftChild; + }else { + + isItALeftChild = false; + + focusNode = focusNode.rightChild; + } + + if(focusNode == null) + return false; + } + + if(focusNode.leftChild == null && focusNode.rightChild == null){ + + if(focusNode == root) + root = null; + + else if(isItALeftChild) + parent.leftChild = null; + + else + parent.rightChild = null; + } + + + else if(focusNode.rightChild == null){ + + if(focusNode == root) + root = focusNode.leftChild; + + else if(isItALeftChild) + parent.leftChild = focusNode.leftChild; + + else + parent.rightChild = focusNode.leftChild; + } + + else if(focusNode.leftChild == null){ + + if(focusNode == root) + root = focusNode.rightChild; + + else if(isItALeftChild) + parent.leftChild = focusNode.leftChild; + + else + parent.rightChild = focusNode.rightChild; + } + + else { + + Node replacement = getReplacementNode(focusNode); + + if(focusNode == root) + root = replacement; + + else if(isItALeftChild) + parent.leftChild = replacement; + + else + parent.rightChild = replacement; + + replacement.leftChild = focusNode.leftChild; + + } + + return true; + } + + public Node getReplacementNode(Node replacedNode){ + + Node replacementParent = replacedNode; + Node replacement = replacedNode; + + Node focusNode = replacedNode.rightChild; + + while(focusNode != null){ + + replacementParent = replacement; + + replacement = focusNode; + + focusNode = focusNode.leftChild; + } + + if(replacement != replacedNode.rightChild){ + + replacementParent.leftChild = replacement.rightChild; + replacement.rightChild = replacedNode.rightChild; + } + + return replacement; + } + + +/** +*The getRootNode method finds the root node for the given Binary Tree +*@param tree The Binary Tree of which you're trying to find the root node +*@return The root node +*/ + public Node getRootNode(){ + return root; + } + + public static void main(String[] args) { + + BinaryTreeDB theTree = new BinaryTreeDB(); + + theTree.addNode(1, "first"); + theTree.addNode(5, "second"); + theTree.addNode(10, "third"); + theTree.addNode(25, "fourth"); + theTree.addNode(50, "fifth"); + theTree.addNode(100, "sixth"); + + BinaryTreeDB theTree1 = new BinaryTreeDB(); + + BinaryTreeDB theTree2 = new BinaryTreeDB(); + System.out.println("ie. Removing 25"); + theTree.remove(25); + theTree.preorderTraverseTree(theTree.root); + } +} diff --git a/production/ClassProject/Database/DatabaseHashTable.java b/production/ClassProject/Database/DatabaseHashTable.java new file mode 100644 index 0000000..95d761b --- /dev/null +++ b/production/ClassProject/Database/DatabaseHashTable.java @@ -0,0 +1,102 @@ +/** +* This class stores the data structure to store an array of values passed to us by middleware. +* If we need to populate the array (or make any other changes), just let Chris or Mike know. +* THIS IS A VERY ROUGH DRAFT +* +* @author Chris Spencer and Mike Opiola +* @version "version-1.0" "150330" +* @since "version-1.0" +*/ + +package edu.oakland.production.ClassProject.Database; + +import java.util.Hashtable; + +public class DatabaseHashTable { + private Hashtable hashTable; + private int[] hashTableElementContainer; + private int[] hashTableArray; + private int hashTableArraySize; + + /*public static void main(String[] args) { + int[] testArray = {1,2,3,4,5,6,7,8,9,10}; + + DatabaseHashTable hashFunction = new DatabaseHashTable(testArray, 20); + + hashFunction.insert(1,101); + System.out.println(hashFunction.select(1)); + hashFunction.remove(1); + System.out.println(hashFunction.select(1)); + + for (int i = 1; i < 10; i++){ + System.out.println(hashFunction.select(i)); + } + } */ + + /** + *Construcor for DatabaseHashTable + */ + DatabaseHashTable(int[] containerArray, int hashArraySize){ + generateHashTable(containerArray, hashArraySize); + } + + /** + *This function generates a hash table based upon an array and hash table size specified + * @param containerArray An array that contains the elements to be added. This will be specified by middleware unless changed + * @param hashArraySize The size of the hash table to be made. This is changeable to allow more flexibility and possible speed improvements. + */ + public void generateHashTable(int[] containerArray, int hashArraySize){ + hashTableElementContainer = containerArray; + hashTableArraySize = hashArraySize; + hashTableArray = new int[hashTableArraySize]; + + hashTable = new Hashtable(); + + for (int i = 0; i < hashTableArray.length; i++){ + hashTableArray[i] = -1; + hashTable.put(i, -1); + } + + for (int j = 0; j < hashTableElementContainer.length; j++){ + int newElementValue = hashTableElementContainer[j]; + int hashTableArrayIndex = newElementValue % (hashTableArray.length - 1); + + System.out.println("Index = " + hashTableArrayIndex + ", Value = " + newElementValue); + + while(hashTableArray[hashTableArrayIndex] != -1){ + ++hashTableArrayIndex; + System.out.println("Collision Occurred. Try " + hashTableArrayIndex + " instead"); + hashTableArrayIndex %= hashTableArraySize; + } + hashTableArray[hashTableArrayIndex] = newElementValue; + hashTable.put(hashTableArrayIndex, newElementValue); + } + + } + + /** + *select takes a key and returns the integer value of what is stored at said key + * @param key Where the hashtable will look to find the value that it will return + * @return int Value found at key + */ + public int select(int key){ + return(hashTable.get(key)); + } + + /** + *remove resets the value of the element with the specified key to -1 + * @param key Where the hashtable will look to find the value to be reset to -1 + */ + public void remove(int key){ + hashTable.put(key, -1); + } + + /** + *insert Takes a value and inserts it into the hash table at the specified key + * @param key Where the hashtable will look to set the value + * @param value The value to be put into the hashtable + */ + public void insert(int key, int value){ + hashTable.put(key, value); + } +} diff --git a/production/ClassProject/Database/LinkedListDB.java b/production/ClassProject/Database/LinkedListDB.java new file mode 100644 index 0000000..79c3733 --- /dev/null +++ b/production/ClassProject/Database/LinkedListDB.java @@ -0,0 +1,154 @@ +package edu.oakland.production.ClassProject.Database; + +/** +*@author Nicholas Herman, Craig Hardy +*@version 1.0 150325 +*@since version 2.0 +*/ + + +/** +*This class provides middleware with the ability to store, get, and set links in +* in a LinkedList. +*/ + +public class LinkedListDB { + + public Link firstLink; + + public LinkedListDB(){ + firstLink = null; + } + + /** + *This method sets the the firstLink to null + */ + public boolean isEmpty(){ + return(firstLink == null); + } + + /** + *This method inserts a link and assigns it to first link + */ + public void insertFirstLink( T obj ){ + + Link newLink = new Link(obj); + + newLink.next = firstLink; + + firstLink = newLink; + } + + /** + *This method removes a link from the linkedList + */ + + public Link removeFirst(){ + + Link linkReference = firstLink; + + if(!isEmpty()){ + + firstLink = firstLink.next; + }else{ + + System.out.println("Empty LinkedList"); + } + + return linkReference; + } + + /** + *This method takes an object as a parameter and finds it in the linked list + */ + + public Link find(T obj){ + + Link theLink = firstLink; + + if(!isEmpty()){ + + while(theLink.getData() != obj){ + + if(theLink.next == null){ + + return null; + }else { + + theLink = theLink.next; + } + } + }else { + + System.out.println("Empty LinkedLint"); + } + return theLink; + } + + /** + *This method takes an object as a parameter, removes it form the list, + * and assigns the nextLink to link + */ + public Link removeLink(T obj){ + + Link currentLink = firstLink; + Link previousLink = firstLink; + + while(currentLink.getData() != obj) { + + if(currentLink.next == null){ + + return null; + }else { + + previousLink = currentLink; + + currentLink = currentLink.next; + + } + } + + if(currentLink == firstLink){ + + firstLink = firstLink.next; + }else{ + + System.out.println("FOUND A MATCH"); + System.out.println("currentLink: " + currentLink); + System.out.println("firstLink: " + firstLink); + + previousLink.next = currentLink.next; + } + + return currentLink; + } + + /** + *This method takes an int and returns the object at that link + */ + public Link get(int id){ + + if (id <= 0) + return null; + + Link currentLink = firstLink.next; + for (int i = 1; i < id; i++) { + if (currentLink.next == null) + return null; + + currentLink = currentLink.next; + } + return currentLink; + } + + /** + * This method replaces existing value at the index with the given value + */ + public void setLink(int index){ + + if (id <= 0) + return; + + Link currentLink = firstLink.next; + } +} diff --git a/production/ClassProject/Database/Node.java b/production/ClassProject/Database/Node.java new file mode 100644 index 0000000..d8353cb --- /dev/null +++ b/production/ClassProject/Database/Node.java @@ -0,0 +1,30 @@ +package edu.oakland.production.ClassProject.Database; + +public class Node { + + int key; + T val; + + Node leftChild; + Node rightChild; + + Node(int key, T value){ + + this.key = key; + + this.val = value; + } + + public T getValue(){ + return val; + } + + public int getKey(){ + return key; + } + + public String toString(){ + + return val + " has a key " + key; + } +} diff --git a/production/ClassProject/Database/StackCut.java b/production/ClassProject/Database/StackCut.java new file mode 100644 index 0000000..ba956c1 --- /dev/null +++ b/production/ClassProject/Database/StackCut.java @@ -0,0 +1,54 @@ +package edu.oakland.production.ClassProject.Database; + +import java.util.*; + +/** + * @version "version 2.0" "20150104" + * @author Sam Bell and Binh Ton + */ +public class StackCut extends Stack{ + private int stackSize; + private Object[] stackArray; + private int topOfStack = -1; + + + public StackCut(int param){ + this.stackSize = param; + stackArray = new Object[stackSize]; + } + + public Object push(Object param) { + if(topOfStack+1=0){ + stackArray[topOfStack]=null; + return stackArray[topOfStack--]; + } + else{ + return null; + } + } + + public void displayStacks(){ + for(int n=0; n= 0) + return stackArray[topOfStack]; + else + return null; + } + +} diff --git a/production/ClassProject/Database/Student.java b/production/ClassProject/Database/Student.java new file mode 100644 index 0000000..227ae5f --- /dev/null +++ b/production/ClassProject/Database/Student.java @@ -0,0 +1,135 @@ +package edu.oakland.production.ClassProject.Database; + +import java.util.*; +/** + * @version "version 2.0" "20150104" + * @author Sam Bell and Binh Ton + */ +public class Student{ + private int gID; + private String name; + private String major; + private double GPA; + private int TG; + + public Student(int gID, String name, String major, double GPA, int TG){ + this.gID = gID; + this.name = name; + this.major = major; + this.GPA = GPA; + this.TG = TG; + } + public int getID(){ + return gID; + } + public String getName(){ + return name; + } + public String getMajor(){ + return major; + } + public double getGPA(){ + return GPA; + } + public int getTG(){ + return TG; + } + public static void main(String [] args){ + Student student1 = new Student(677422, "Jones", "IT", 3.82, 95); + Student student2 = new Student(177993, "Smith", "IT", 3.47, 78); + Student student3 = new Student(444811, "Breaux", "CS", 3.95, 98); + Student student4 = new Student(113625, "Brady", "CS", 3.77, 92); + Student student5 = new Student(382707, "Rominske", "CS", 3.82, 79); + Student student6 = new Student(447447, "Hardy", "IT", 3.68, 99); + Student student7 = new Student(661284, "Kominsky", "IT", 3.23, 70); + Student student8 = new Student(855462, "O'Brien", "IT", 3.44, 85); + Student student9 = new Student(223344, "Chamberlain", "CS", 3.99, 96); + Student student10 = new Student(348689, "Grant", "CS", 3.88, 99); + StackCut stackcut = new StackCut(10); + + stackcut.push(student1.getID()); + stackcut.push(student2.getID()); + stackcut.push(student3.getID()); + stackcut.push(student4.getID()); + stackcut.push(student5.getID()); + stackcut.push(student6.getID()); + stackcut.push(student7.getID()); + stackcut.push(student8.getID()); + stackcut.push(student9.getID()); + stackcut.push(student10.getID()); + + System.out.println("The current stack is: "); + stackcut.displayStacks(); + System.out.println(); + + for(int i=0;i<5;i++){ + Object sgid = stackcut.peek(); + int h = (Integer) sgid; + if(h == student1.getID()){ + System.out.println("Student of name: "+student1.getName()+" and GID: "+student1.getID()+" was removed from the list."); + System.out.println(student1.getName()+" had a major of: "+student1.getMajor()+" a GPA of: "+student1.getGPA()+" and a thesis grade of: "+student1.getTG()); + System.out.println(); + } + if(h == student2.getID()){ + System.out.println("Student of name: "+student2.getName()+" and GID: "+student2.getID()+" was removed from the list."); + System.out.println(student2.getName()+" had a major of: "+student2.getMajor()+" a GPA of: "+student2.getGPA()+" and a thesis grade of: "+student2.getTG()); + System.out.println(); + } + if(h == student3.getID()){ + System.out.println("Student of name: "+student3.getName()+" and GID: "+student3.getID()+" was removed from the list."); + System.out.println(student3.getName()+" had a major of: "+student3.getMajor()+" a GPA of: "+student3.getGPA()+" and a thesis grade of: "+student3.getTG()); + System.out.println(); + } + if(h == student4.getID()){ + System.out.println("Student of name: "+student4.getName()+" and GID: "+student4.getID()+" was removed from the list."); + System.out.println(student4.getName()+" had a major of: "+student4.getMajor()+" a GPA of: "+student4.getGPA()+" and a thesis grade of: "+student4.getTG()); + System.out.println(); + } + if(h == student5.getID()){ + System.out.println("Student of name: "+student5.getName()+" and GID: "+student5.getID()+" was removed from the list."); + System.out.println(student5.getName()+" had a major of: "+student5.getMajor()+" a GPA of: "+student5.getGPA()+" and a thesis grade of: "+student5.getTG()); + System.out.println(); + } + if(h == student6.getID()){ + System.out.println("Student of name: "+student6.getName()+" and GID: "+student6.getID()+" was removed from the list."); + System.out.println(student6.getName()+" had a major of: "+student6.getMajor()+" a GPA of: "+student6.getGPA()+" and a thesis grade of: "+student6.getTG()); + System.out.println(); + } + if(h == student7.getID()){ + System.out.println("Student of name: "+student7.getName()+" and GID: "+student7.getID()+" was removed from the list."); + System.out.println(student7.getName()+" had a major of: "+student7.getMajor()+" a GPA of: "+student7.getGPA()+" and a thesis grade of: "+student7.getTG()); + System.out.println(); + } + if(h == student8.getID()){ + System.out.println("Student of name: "+student8.getName()+" and GID: "+student8.getID()+" was removed from the list."); + System.out.println(student8.getName()+" had a major of: "+student8.getMajor()+" a GPA of: "+student8.getGPA()+" and a thesis grade of: "+student8.getTG()); + System.out.println(); + } + if(h == student9.getID()){ + System.out.println("Student of name: "+student9.getName()+" and GID: "+student9.getID()+" was removed from the list."); + System.out.println(student9.getName()+" had a major of: "+student9.getMajor()+" a GPA of: "+student9.getGPA()+" and a thesis grade of: "+student9.getTG()); + System.out.println(); + } + if(h == student10.getID()){ + System.out.println("Student of name: "+student10.getName()+" and GID: "+student10.getID()+" was removed from the list."); + System.out.println(student10.getName()+" had a major of: "+student10.getMajor()+" a GPA of: "+student10.getGPA()+" and a thesis grade of: "+student10.getTG()); + System.out.println(); + } + stackcut.pop(); + } + System.out.println(); + System.out.println("The stack after the cut is: "); + stackcut.displayStacks(); + System.out.println(); + Object unluckystudentone =stackcut.peek(); + stackcut.pop(); + Object unluckystudenttwo = stackcut.peek(); + stackcut.pop(); + System.out.println("The stack after the cut is: "); + stackcut.displayStacks(); + System.out.println(); + System.out.println("The student with GID: "+unluckystudentone+" did not recieve the scholarship."); + System.out.println("The student with GID: "+unluckystudenttwo+" also did not recieve the scholarship."); + + } +} \ No newline at end of file diff --git a/production/ClassProject/Display/.DS_Store b/production/ClassProject/Display/.DS_Store new file mode 100644 index 0000000..a54e3f9 Binary files /dev/null and b/production/ClassProject/Display/.DS_Store differ diff --git a/production/ClassProject/Display/Display.java b/production/ClassProject/Display/Display.java new file mode 100644 index 0000000..f353637 --- /dev/null +++ b/production/ClassProject/Display/Display.java @@ -0,0 +1,548 @@ +package edu.oakland.production.ClassProject.Display; + +import java.util.*; +import edu.oakland.production.ClassProject.Middleware.Middleware; + +/** + * + * @author Display Group + * @version 3.0 Integration with Middleware + * @since 3/30/2015 + */ +public class Display +{ + Middleware mw = new Middleware(); + Scanner scan = new Scanner(System.in); + int first; + int second; + int third; + /** + * Constructor + */ + public Display(){ + + } + + public void mainMenu(){ + + scan = new Scanner(System.in); + boolean stayIn = true; + do{ + + System.out.println("What do you want to do, 1,2,3,4"); + System.out.println("1 Create ArrayList and LinkedList and Search"); + System.out.println("2 Create Binary and Search"); + System.out.println("3 Create HashTable and Search"); + System.out.println("4 Class Schedule"); + System.out.println("Anything else will quit."); + + + switch (scan.next()) + { + case "1": + Lists(); + System.out.println("lists done"); + break; + + case "2": + BinaryTree(); + System.out.println("Binary Completed"); + break; + case "3": + HashTable(); + System.out.println("Hash Completed"); + break; + case "4": + SchedulingClass(); + System.out.println("Schedule Completed"); + break; + case "5": + stayIn = false; + break; + default: + System.out.println("Invalid Entry"); + } + + if (stayIn == false){ + System.out.println("Exit"); + break; + } + + System.out.println("Would you like to do another search? (y/n) search"); + switch (scan.next()) + { + case "y": + break; + case "n": + default: + stayIn = false; + break; + } + + + }while (stayIn); + System.out.println("Exit program"); + scan.close(); + } + + public void lists(){ + boolean stayIn = true; + boolean notSuccessful = true; + boolean invalidOption = false; + int numberOfElements; + int element; + String tempToParse; + do{ + + System.out.println("Choose the amount of elements for your arraylist and linkedlist: "); + System.out.println("1.) 100,000 Elements (1)"); + System.out.println("2.) 200,000 Elements (2)"); + System.out.println("3.) 400,000 Elements (3)"); + System.out.println("4.) Exit ArrayList and LinkedList Menu (4)"); + System.out.print(""); + + switch (scan.next()) + { + case "1": + numberOfElements = 100000; + System.out.println("You have selected 100,000 elements"); + break; + case "2": + numberOfElements = 200000; + System.out.println("You have selected 200,000 elements"); + break; + case "3": + numberOfElements = 400000; + System.out.println("You have selected 400,000 elements"); + break; + case "4": + stayIn = false; + break; + default: + System.out.println("Invalid Entry"); + invalidOption = true; + break; + + } + + if (stayIn == false){ + System.out.println("Exit"); + break; + } + + if (!invalidOption){ + + //Linked List + mw.LinkedListMiddleware(numberofElements); + //Select Sort + String timeLinkedSelectSort = mw.LinkedListSelectSort(); + System.out.println("It took " + timeLinkedSelectSort + " ms to sort the Linked List by Select sort"); + String bigOhLinkedSelectSort = mw.LinkedListSelectBigOh(); + System.out.println("Select Sort BIG OH is " + bigOhLinkedSelectSort); + + //Bubble Sort + String timeLinkedBubbleSort = mw.LinkedListBubbleSort(); + System.out.println("It took " + timeLinkedBubbleSort + " ms to sort the Linked List by Bubble sort"); + String bigOhLinkedBubbleSort = mw.LinkedListBubbleBigOh(); + System.out.println("Bubble Sort BIG OH is " + bigOhLinkedBubbleSort); + + //Array List + mw.ArrayListMiddleware(numberofElements); + //Select Sort + String timeArraySelectSort = mw.ArrayListSelectSort(); + System.out.println("It took " + timeArraySelectSort + " ms to sort the Array List by Select sort"); + String bigOhArraySelectSort = mw.ArrayListSelectBigOh(); + System.out.println("Select Sort BIG OH is " + bigOhArraySelectSort); + + //Bubble Sort + String timeArrayBubbleSort = mw.ArrayListBubbleSort(); + System.out.println("It took " + timeArrayBubbleSort + " ms to sort the Array List by Bubble sort"); + String bigOhArrayBubbleSort = mw.LinkedListArrayBigOh(); + System.out.println("Bubble Sort BIG OH is " + bigOhArrayBubbleSort); + + System.out.println("What element do you want to see?"); + tempToParse = scan.next(); + + do{ + try{ + element = Integer.parseInt(tempToParse); + notSuccessful = false; + } catch (Exception e) { + System.out.println("NOT A VALID NUMBER, GIVE A NUMBER"); + tempToParse = scan.next(); + } + } while (notSuccessful); + notSuccessful = true; + + String linearTimes = mw.linearSearch(element); + String binaryTimes = mw.binarySearch(element); + + } + invalidOption = false; + + System.out.println("Would you like to do another LinkedList search? (y/n) search"); + switch (scan.next()) + { + case "y": + break; + case "n": + default: + stayIn = false; + break; + } + + + } while(stayIn); + } + + public void binaryTree(){ + + boolean stayIn = true; + String temp; + int numberOfElements; + boolean invalidOption = false; + + do{ + System.out.println("Choose the number of elements."); + System.out.println("1. 100k Elements (1)"); + System.out.println("2. 200k Elements (2)"); + System.out.println("3. 400k Elements (3)"); + System.out.println("4. Exit to main menu (4)"); + System.out.print(""); + + String response = scan.next(); + + if (response.equals("4")){ + stayIn = false; + break; + } + + switch(response) + { + case "1": + numberOfElements = 100000; + break; + case "2": + numberOfElements = 200000; + break; + case "3": + numberOfElements = 400000; + break; + case "4": + stayIn = false; + break; + default : + System.out.println("Did not choose a correct version"); + invalidOption = true; + break; + } + + if (stayIn == false){ + System.out.println("Exit"); + break; + } + + if (!invalidOption){ + mw.createBinaryTree(numberofElements); + // SELECT 3 Ints + if (first == "" && second == "" && third == "") + { + System.out.println("What is the first string to search?"); + first = scan.nextInt(); + System.out.println("What is the second string to search?"); + second = scan.nextInt(); + System.out.println("What is the third string to search?"); + third = scan.nextInt(); + } + else + { + System.out.println("Values of the search have been set, replace? (y/n)"); + temp = scan.next(); + if ("y".equals(response)) + { + System.out.println("What is the first string to search?"); + first = scan.nextInt(); + System.out.println("What is the second string to search?"); + second = scan.nextInt(); + System.out.println("What is the third string to search?"); + third = scan.nextInt(); + } + } + invalidOption = false; + + // PREORDER SEARCH + mw.calculatePreorderNodesSearched(first, second, third); + + // ORDER SEARCH + mw.calculateInOrderNodesSearched(first, second, third); + + // Duration + mw.calculatePreorderSearchDuration(first, second, third); + mw.calculateInOrderSearchDuration(first, second, third); + + // Get BigOh Relationship + mw.calculateBigORelationship(); + } + + System.out.println("Would you like to do another search? (y/n)"); + response = scan.next(); + if ("y".equals(response)) + { + //Run again + } + else + { + stayIn = false; + break; + } + + + } while (stayIn); + } + + public void hashTable(){ + boolean stayIn = true; + String temp; + int numberOfElements; + boolean invalidOption = false; + do{ + + System.out.println("Choose the amount of elements for your Random HashTable: "); + System.out.println("1.) 100,000 Elements (1)"); + System.out.println("2.) 200,000 Elements (2)"); + System.out.println("3.) 400,000 Elements (3)"); + System.out.println("4.) Exit Hashtable Menu (4)"); + System.out.print(""); + + switch (scan.next()) + { + case "1": + numberOfElements = 100000; + break; + case "2": + numberOfElements = 200000; + break; + case "3": + numberOfElements = 400000; + break; + case "4": + stayIn = false; + break; + default : + System.out.println("Did not choose a correct version"); + invalidOption = true; + break; + } + + if (stayIn == false){ + System.out.println("Exit"); + break; + } + + if (!invalidOption){ + mw.createHashTable(numberofElements); + // SELECT 3 Int + if (first == "" && second == "" && third == "") + { + System.out.println("What is the first int to search?"); + first = scan.nextInt(); + System.out.println("What is the second int to search?"); + second = scan.next(); + System.out.println("What is the third int to search?"); + third = scan.next(); + } + else + { + System.out.println("Values of the search have been set, replace? (y/n)"); + temp = scan.next(); + if ("y".equals(temp)) + { + System.out.println("What is the first int to search?"); + first = scan.next(); + System.out.println("What is the second int to search?"); + second = scan.next(); + System.out.println("What is the third int to search?"); + third = scan.next(); + } + } + invalidOption = false; + + + // PREORDER SEARCH + // searchPreorderHash(first, second, third); + // ORDER SEARCH + // searchOrderedHash(first, second, third); + // GET TIME ELAPSED + // timeElapsedHash(); + // GET BIG O RELATIONSHIP + // bigOHash(); + } + + + + + System.out.println("Would you like to do another hashtable search? (y/n) search"); + switch (scan.next()) + { + case "y": + break; + case "n": + default: + stayIn = false; + break; + } + + + } while(stayIn); + } + + public void schedulingClass(){ + boolean isClassMade = false; + boolean stayIn = true; + do { + System.out.println("Select an option"); + System.out.println("1.) Input student data into class. Enter 1"); + System.out.println("2.) Cut Last 5 students Enter 2"); + System.out.println("3.) Process Scholarships Enter 3"); + System.out.println("4.) Reinstate Students to class Enter 4"); + System.out.println("5.) Exit Enter 5" ); + String response = scan.next(); + String temp = ""; + + if ("5".equals(response)){ + stayIn = false; + } + else if (!"1".equals(response) && isClassMade == false){ + System.out.println("Class has not been made yet. Do you want to make the class? (y/n)"); + response = scan.next(); + if ("y".equals(response)) + { + temp = mw.CreateClass(); + isClassMade = true; + } + + } + else{ + + switch(response) + { + case "1": + if (isClassMade){ + System.out.println("Class already was made, do you want to enter new data? (y/n)"); + if ("y".equals(response)) + { + //CLEAR + createClass(); + isClassMade = true; + } + } + else{ + createClass(); + System.out.println("Class Made"); + isClassMade = true; + } + break; + case "2": + temp = mw.CutClass(); + System.out.println("Cut Class"); + break; + case "3": + temp = mw.Scholarship(); + System.out.println("Scholar"); + break; + case "4": + temp = mw.ResetClass(); + System.out.println("Reset Class"); + break; + default: + System.out.println("Invalid entry."); + } + System.out.println("Would you like to do continue in the class edit menu? (y/n)"); + response = scan.next(); + if ("y".equals(response)) + { + //Run again + } + else + { + stayIn = false; + } + } + + }while(stayIn); + + } + + private void createClass(){ + + boolean stayIn = true; + + do{ + boolean notSuccessful = true; + String tempToParse; + String temp; + int grizzlyID; + String name; + String major; + double gpa; + int thesisGrade; + System.out.println("Enter student data:"); + System.out.println("What is the student's Grizzly ID?"); + tempToParse = scan.next(); + do{ + try{ + grizzlyID = Integer.parseInt(tempToParse); + notSuccessful = false; + } catch (Exception e) { + System.out.println("ID Entered is not a valid number, What is the student's Grizzly ID?"); + tempToParse = scan.next(); + } + } while (notSuccessful); + notSuccessful = true; + + System.out.println("What is the student's name?"); + name = scan.next(); + System.out.println("What is the major of the student"); + major = scan.next(); + + System.out.println("What is the GPA"); + tempToParse = scan.next(); + do{ + try{ + gpa = Double.parseDouble(tempToParse); + notSuccessful = false; + } catch (Exception e) { + System.out.println("GPA Entered is not a valid number, What is the GPA?"); + tempToParse = scan.next(); + } + } while (notSuccessful); + notSuccessful = true; + System.out.println("Thesis grade?"); + tempToParse = scan.next(); + do{ + try{ + thesisGrade = Integer.parseInt(tempToParse); + notSuccessful = false; + } catch (Exception e) { + System.out.println("Thesis Entered is not a valid number, What is the student's thesis grade?"); + tempToParse = scan.next(); + } + } while (notSuccessful); + notSuccessful = true; + + /// CREATE STUDENT + + + System.out.println("Would you like to do continue in the class edit menu? (y/n)"); + temp = scan.next(); + if ("y".equals(temp)) + { + //Run again + } + else + { + stayIn = false; + } + } while (stayIn); + } +} diff --git a/LICENSE b/production/ClassProject/LICENSE similarity index 100% rename from LICENSE rename to production/ClassProject/LICENSE diff --git a/production/ClassProject/Middleware/ArrayListDatabase.java b/production/ClassProject/Middleware/ArrayListDatabase.java new file mode 100644 index 0000000..f21b186 --- /dev/null +++ b/production/ClassProject/Middleware/ArrayListDatabase.java @@ -0,0 +1,55 @@ +package edu.oakland.production.ClassProject; + +import java.util.*; + + +/** +*@author Eldari Gogiashvili +*@version version 1.0.1 date 150331 +*since version 1.0.0 +*/ + +/** +*This class represents the middleware +*/ + +public class ArrayListDatabase{ + + ArrayList students; + + ArrayListDatabase(int size){ + students = new ArrayList(size); + } + + + public Integer getStudent(int i){ + return students.get(i); + } + + + public void setStudent(int i, int j){ + students.add(i,j); + } + + + public void addStudent(int i){ + students.add(i); + } + + + public void removeStudent(int i){ + students.remove(i); + } + + + public int returnSize(){ + return students.size(); + } + + public void clearAllStudents(){ + students.clear(); + } +} +/** +*This class was created for Middleware. +*/ \ No newline at end of file diff --git a/production/ClassProject/Middleware/ArrayListMockDisplay.java b/production/ClassProject/Middleware/ArrayListMockDisplay.java new file mode 100644 index 0000000..8e8ae60 --- /dev/null +++ b/production/ClassProject/Middleware/ArrayListMockDisplay.java @@ -0,0 +1,33 @@ +package edu.oakland.production.ClassProject; + +import edu.oakland.production.ClassProject.*; +/** +*@author Eldari Gogiashvili +*@version version 1.0.1 date 150331 +*since version 1.0.0 +*/ + +/** +*This class represents the middleware +*/ + +public class ArrayListMockDisplay { + public void main(String[] args){ + + int ListSize = 100; + int searchKey = 100; + + /** + *Constructor for Middleware. + */ + MidArrayList mw = new MidArrayList(ListSize); + mw.selectionSort(); + mw.linearSearch(searchKey); + mw.binarySearch(searchKey); + + MidArrayList mw1 = new MidArrayList(ListSize); + mw1.bubbleSort(); + mw1.linearSearch(searchKey); + mw1.binarySearch(searchKey); + } +} \ No newline at end of file diff --git a/production/ClassProject/Middleware/BinaryTree.java b/production/ClassProject/Middleware/BinaryTree.java new file mode 100644 index 0000000..62ecdf8 --- /dev/null +++ b/production/ClassProject/Middleware/BinaryTree.java @@ -0,0 +1,62 @@ +package edu.oakland.production.ClassProject.middleware; + +public class BinaryTree{ + + public Node root; + + public void addNode(String name, double gpa, int tg){ + Node newNode = new Node(name, gpa, tg); + if(root == null){ + root = newNode; + } + else{ + Node focusNode = root; + Node parent; + while(true){ + parent = focusNode; + if(tg < focusNode.tg){ + focusNode = focusNode.leftChild; + + if(focusNode == null){ + parent.leftChild = newNode; + return; + } + } + else { + focusNode = focusNode.rightChild; + if(focusNode == null){ + parent.rightChild = newNode; + return; + } + } + } + } + } + + public void preorderTraverseTree(Node focusNode){ + if(focusNode != null){ + System.out.println(focusNode); + preorderTraverseTree(focusNode.leftChild); + preorderTraverseTree(focusNode.rightChild); + } + } + + public Node findNode(int tg){ + Node focusNode = root; + while(focusNode.tg != tg){ + if(tg > focusNode.tg){ + return focusNode; + } + if(tg < focusNode.tg){ + focusNode = focusNode.leftChild; + } + else{ + focusNode = focusNode.rightChild; + } + } + return focusNode; + + } + + } + diff --git a/production/ClassProject/Middleware/BinaryTreeMW.java b/production/ClassProject/Middleware/BinaryTreeMW.java new file mode 100644 index 0000000..f2a68a4 --- /dev/null +++ b/production/ClassProject/Middleware/BinaryTreeMW.java @@ -0,0 +1,467 @@ +package edu.oakland.production.ClassProject.Middleware; + +//Import java util framework +import java.util.*; + +//Import BinaryTreeDB.java & Node.java +import edu.oakland.production.ClassProject.Database.*; + + +/* + * BinaryTreeMW. + * + * @author Joshua Herkness, Trevor Luebbert Middleware + * @version version 2.0 + * @since version 1.0 + */ +public class BinaryTreeMW { + + /// Minimum possible key value, used with generating a random key. + private int minimumKeyValue = 400000; + /// Maximum possible key value, used with generating a random key. + private int maximumKeyValue = 800000; + + /// Minimum possible name value, used with generating a random name. + private int minimumNameValue = 200000; + /// Maximum possible key value, used with generating a random name. + private int maximumNameValue = 600000; + + private BinaryTreeDB binaryTreeDatabase; + + /* + * Default constructor for the BinaryTreeMW Class. + * + * @returns BinaryTreeMW + */ + public BinaryTreeMW(){ + + this.binaryTreeDatabase = new BinaryTreeDB(); + } + + /* + * Overloaded constructor for the BinaryTreeMW Class. Popluates the binaryTreeDatabase given a size. + * + * @param size Integer value corresponding to the desired size of the BinaryTreeDB object. + * + * @returns BinaryTreeMW + */ + public BinaryTreeMW(int size){ + + this.binaryTreeDatabase = new BinaryTreeDB(); + + // Populates the BinaryTreeDB object + populateBinaryTreeDB(size); + } + + /* + * Populates a private global BinaryTreeDB object with a given amount of nodes. Creates a non-duplicate random key and name for each node. + * + * @param size Integer value corresponding to the size of the binary tree. + * + */ + public void populateBinaryTreeDB(int size){ + + // Refresh the BinaryTreeDB object. + this.binaryTreeDatabase = new BinaryTreeDB(); + + // Create a non-duplicate random number list for keys. + List nonDuplicateRandomNumberKeys = new ArrayList(); + // Create a non-duplicate random number list for names. + List nonDuplicateRandomNumberNames = new ArrayList(); + + // Populate both key and name lists. + nonDuplicateRandomNumberKeys = createNonDuplicateRandomNumbers(minimumKeyValue, maximumKeyValue, size); + nonDuplicateRandomNumberNames = createNonDuplicateRandomNumbers(minimumNameValue, maximumNameValue, size); + + for (int i = 0; i < size; i++){ + + // Reference key integer from a given index. + int key = nonDuplicateRandomNumberKeys.get(i); + // Reference name integer from a given index, then convert to a string. + String name = String.valueOf(nonDuplicateRandomNumberNames.get(i)); + + // Add a node to the BinaryTreeDB, given the key and name. + this.binaryTreeDatabase.addNode(key, name); + + } + } + + /* + * Searches for three integer key values, providing a record of the amount of nodes searched durring a preorder search. + * + * @param key1 Integer value corresponding to a key value. + * @param key2 Integer value corresponding to a key value. + * @param key3 Integer value corresponding to a key value. + * + * @returns nodesSearched String value corresponding to the number of nodes searched respectively. + */ + public String calculatePreorderNodesSearched(int key1, int key2, int key3){ + + String nodesSearched = ""; + + Node focusNode = this.binaryTreeDatabase.getRootNode(); + + nodesSearched += String.valueOf(calculatePreorderNodesSearched(this.binaryTreeDatabase, focusNode, key1)); + nodesSearched += " "; + + nodesSearched += String.valueOf(calculatePreorderNodesSearched(this.binaryTreeDatabase, focusNode, key2)); + nodesSearched += " "; + + nodesSearched += String.valueOf(calculatePreorderNodesSearched(this.binaryTreeDatabase, focusNode, key3)); + + return nodesSearched; + } + + /* + * Searches for three integer key values, providing a record of the amount of nodes searched durring an in order search. + * + * @param key1 Integer value corresponding to a key value. + * @param key2 Integer value corresponding to a key value. + * @param key3 Integer value corresponding to a key value. + * + * @returns nodesSearched String value corresponding to the number of nodes searched respectively. + */ + public String calculateInOrderNodesSearched(int key1, int key2, int key3){ + + String nodesSearched = ""; + + Node focusNode = this.binaryTreeDatabase.getRootNode(); + + nodesSearched += String.valueOf(calculateInOrderNodesSearched(this.binaryTreeDatabase, focusNode, key1)); + nodesSearched += " "; + + nodesSearched += String.valueOf(calculateInOrderNodesSearched(this.binaryTreeDatabase, focusNode, key2)); + nodesSearched += " "; + + nodesSearched += String.valueOf(calculateInOrderNodesSearched(this.binaryTreeDatabase, focusNode, key3)); + + return nodesSearched; + } + + /* + * Calculates the amount of nodes searched for locating a given key using a preorder search. + * + * @param binaryTreeDatabase BinaryTreeDB object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * + * @returns int Integer type corresponding to the number of nodes searched through. + */ + private int calculatePreorderNodesSearched(BinaryTreeDB binaryTreeDatabase, Node focusNode, int key){ + + int nodesSearched = calculatePreorderNodesSearched(binaryTreeDatabase, focusNode, key, true); + + return nodesSearched; + + } + + /* + * Helper recursive method used to calculates the amount of nodes searched for locating a given key using a preorder search. + * + * @param binaryTreeDatabase BinaryTreeDB object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * @param continueSearch Boolean value corresponding to whether the node has been located. + * + * @returns int Integer type corresponding to the number of nodes searched through. + */ + private int calculatePreorderNodesSearched(BinaryTreeDB binaryTreeDatabase, Node focusNode, int key, boolean continueSearching){ + + // Begin each recursion with zero nodes searched. + int nodesSearched = 0; + + // Ignore the recursion loop if the node is already found, or if the node is non existant. + if (!continueSearching){ + return 0; + } else if (focusNode == null){ + return 0; + } else { + // Count the node. + nodesSearched++; + } + + // If the focus node has the desired key, increament the amount of nodesSearched, and skip all other recursions. + if (focusNode.getKey() == key){ + + continueSearching = false; + return nodesSearched; + + } + + if (focusNode.leftChild != null){ + nodesSearched += calculatePreorderNodesSearched(binaryTreeDatabase, focusNode.leftChild, key, continueSearching); + } + + if (focusNode.rightChild != null){ + nodesSearched += calculatePreorderNodesSearched(binaryTreeDatabase, focusNode.rightChild, key, continueSearching); + } + + return nodesSearched; + + } + + /* + * Calculates the amount of nodes searched for locating a given key using an in order search. + * + * @param binaryTreeDatabase BinaryTreeDB object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * + * @returns int Integer type corresponding to the number of nodes searched through. + */ + private int calculateInOrderNodesSearched(BinaryTreeDB binaryTreeDatabase, Node focusNode, int key){ + + int nodesSearched = calculateInOrderNodesSearched(binaryTreeDatabase, focusNode, key, true); + + return nodesSearched; + } + + /* + * Helper recursive method used to calculates the amount of nodes searched for locating a given key using an in order search. + * + * @param binaryTreeDatabase BinaryTreeDB object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * @param continueSearch Boolean value corresponding to whether the node has been located. + * + * @returns int Integer type corresponding to the number of nodes searched through. + */ + private int calculateInOrderNodesSearched(BinaryTreeDB binaryTreeDatabase, Node focusNode, int key, boolean continueSearching){ + + // Begin each recursion with zero nodes searched. + int nodesSearched = 0; + + // Ignore the recursion loop if the node is already found, or if the node is non existant. + if (!continueSearching){ + return 0; + } else if (focusNode == null){ + return 0; + } else { + // Count the node. + nodesSearched++; + } + + if (focusNode.leftChild != null){ + nodesSearched += calculateInOrderNodesSearched(binaryTreeDatabase, focusNode.leftChild, key, continueSearching); + } + + // If the focus node has the desired key, increament the amount of nodesSearched, and + if (focusNode.getKey() == key){ + + continueSearching = false; + return nodesSearched; + + } + + if (focusNode.rightChild != null){ + nodesSearched += calculateInOrderNodesSearched(binaryTreeDatabase, focusNode.rightChild, key, continueSearching); + } + + return nodesSearched; + } + + /* + * Calculates the amount of time (in milliseconds) needed to conduct a preorder search on each of the three integer keys provided. + * + * @param key1 Integer value corresponding to a key value. + * @param key2 Integer value corresponding to a key value. + * @param key3 Integer value corresponding to a key value. + * + * @returns duration String value corresponding to the time elapsed durring each of the searches respectively. + */ + public String calculatePreorderSearchDuration(int key1, int key2, int key3){ + + String duration = ""; + + Node focusNode = this.binaryTreeDatabase.getRootNode(); + + duration += Double.toString(calculatePreorderSearchDuration(this.binaryTreeDatabase, focusNode, key1)); + duration += " "; + + duration += Double.toString(calculatePreorderSearchDuration(this.binaryTreeDatabase, focusNode, key2)); + duration += " "; + + duration += Double.toString(calculatePreorderSearchDuration(this.binaryTreeDatabase, focusNode, key3)); + + return duration; + } + + /* + * Calculates the amount of time (in milliseconds) needed to conduct an in order search on each of the three integer keys provided. + * + * @param key1 Integer value corresponding to a key value. + * @param key2 Integer value corresponding to a key value. + * @param key3 Integer value corresponding to a key value. + * + * @returns duration String value corresponding to the time elapsed durring each of the searches respectively. + */ + public String calculateInOrderSearchDuration(int key1, int key2, int key3){ + + String duration = ""; + + Node focusNode = this.binaryTreeDatabase.getRootNode(); + + duration += Double.toString(calculateInOrderSearchDuration(this.binaryTreeDatabase, focusNode, key1)); + duration += " "; + + duration += Double.toString(calculateInOrderSearchDuration(this.binaryTreeDatabase, focusNode, key2)); + duration += " "; + + duration += Double.toString(calculateInOrderSearchDuration(this.binaryTreeDatabase, focusNode, key3)); + + return duration; + } + + /* + * Calculates the amount of time (in milliseconds) needed to conduct a preorder search on the integer key provided. + * + * @param binaryTreeDatabase BinaryTreeDB object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * + * @returns double Double type corresponding to time taken to search the binaryTreeDatabase. + */ + private double calculatePreorderSearchDuration(BinaryTreeDB binaryTreeDatabase, Node focusNode, int key){ + + double startTime = System.currentTimeMillis(); + int temporary = calculatePreorderNodesSearched(binaryTreeDatabase, focusNode, key); + double endTime = System.currentTimeMillis(); + + return (endTime - startTime); + } + + /* + * Calculates the amount of time (in milliseconds) needed to conduct an in order search on the key provided. + * + * @param binaryTreeDatabase BinaryTreeDB object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * + * @returns double Double type corresponding to time taken to search the binaryTreeDatabase. + */ + private double calculateInOrderSearchDuration(BinaryTreeDB binaryTreeDatabase, Node focusNode, int key){ + + double startTime = System.currentTimeMillis(); + int temporary = calculateInOrderNodesSearched(binaryTreeDatabase, focusNode, key); + double endTime = System.currentTimeMillis(); + + return (endTime - startTime); + } + + /* + * Gathers data for the BigO notaion, returning a string of the duration spent searching after each recursion, as well as the description of the notation. + * + * @returns bigO String value corresponding to the big O notation and data set as proof. + */ + public String calculateBigORelationship(){ + + Node focusNode = this.binaryTreeDatabase.getRootNode(); + + String bigO = ""; + + // Description of the BigO notation. + bigO += "After each recursion, the time spent searching is halved" + + "since you can only move down either the left or right child nodes." + + "This halving of the data can be represented as O (log N)"; + + // Introduction to the data set + bigO += "\nThe time spent searching during each recursion are as follows:\n"; + + //the key is -1 so the search method goes through the entire tree + bigO += calculateInOrderTimeElapsed(focusNode, -1, true); + + return bigO; + } + + /* + * Calculates durration of each recursion of the method. + * + * @param binaryTreeDatabase BinaryTreeDB object. + * @param focusNode Node object. + * @param key Integer value corresponding to the key of a given node object. + * @param continueSearching Boolean value that tells the method whether or not it needs to continue searching. + * + * @returns time String value that returns data regarding time spent during each recursion of the method. + */ + private String calculateInOrderTimeElapsed(Node focusNode, int key, boolean continueSearching){ + + String time = ""; + + //Capture the start time. + double startTime = System.currentTimeMillis(); + + // Ignore the recursion loop if the node is already found, or if the node is non existant. + if (!continueSearching){ + return ""; + } else if (focusNode == null){ + return ""; + } + + if (focusNode.leftChild != null){ + time += " "; + time += calculateInOrderTimeElapsed(focusNode.leftChild, key, continueSearching); + } + + // If the focus node has the desired key, stop searching + if (focusNode.getKey == key){ + continueSearching = false; + } + + if (focusNode.rightChild != null){ + time += " "; + time += calculateInOrderTimeElapsed(focusNode.rightChild, key, continueSearching); + } + + double endTime = System.currentTimeMillis(); + + time += " "; + time += (Double.toString(endTime-startTime)); + return time; + } + + /* + * Generates a non-duplicate random number list, given a minimumValue, maximumValue, and size. + * + * @param minimumValue Integer value corresponding to the minimum possible random value generated. + * @param maximumValue Integer value corresponding to the maximum possible random value generated. + * + * @returns List List type, shuffled to mimic non-duplicate random numbers. + */ + private List createNonDuplicateRandomNumbers(int minimumValue, int maximumValue, int size){ + + // Create an instance of ArrayList, with type int. + ArrayList nonDuplicateRandomNumbers = new ArrayList(); + + //Test for errors with provided data. If there arent enough possible numbers, return null. + if ((maximumValue - minimumValue) < size){ + + //There has been an error. + return null; + + } + + // For the range of numbers provided. + // Creates an ArrayList of integers from minimumValue to maximumValue. + for (int i = minimumValue; i <= maximumValue; i++){ + + // Add that number to the ArrayList. + nonDuplicateRandomNumbers.add(i); + } + + // Shuffle the ArrayList, randomizing the numbers. + Collections.shuffle(nonDuplicateRandomNumbers); + + // Return a immutable List object, created from the ArrayList, trimming off unnecessary values. + return nonDuplicateRandomNumbers.subList(0, size - 1); + } + + /* + * Retrieves the BinaryTreeDatabaseObject. + * + * @returns BinaryTreeDB + */ + public BinaryTreeDB getBinaryTreeDatabase(){ + + return this.binaryTreeDatabase; + } +} \ No newline at end of file diff --git a/production/ClassProject/Middleware/HashClient.java b/production/ClassProject/Middleware/HashClient.java new file mode 100644 index 0000000..fb02029 --- /dev/null +++ b/production/ClassProject/Middleware/HashClient.java @@ -0,0 +1,67 @@ +package edu.oakland.production.GroupProject.Middleware; + +import java.util.*; +import edu.oakland.production.GroupProject.Middleware.*; + +/** + * @author Dean DeHart, Middleware + * @version 2.0 150401 + * @since 1.0 150328 + */ +public class HashClient { + /** + * Creates an instance of the Database HashTable class. + * Error is currently caused by missing import statement for this class. -Dean + */ + private HashTable hashTable; + /** + * Creates an instance of the Middleware HashArrayCreator class, located in the + * edu.oakland.production.GroupProject.Middleware package. -Dean + */ + private HashArrayCreator hashArrayCreator; + /** + * Creates an instance of the Middleware HashDataFinder class, located in the + * edu.oakland.production.GroupProject.Middleware package. -Dean + */ + private HashFinder hashFinder; + /** + * Creates an instance of the Middleware HashClient class, located in the + * edu.oakland.production.GroupProject.Middleware package. -Dean + */ + private HashClient hashClient = new HashClient(); + /** + *See findHashTableValue(); -Dean + */ + private int[] hashTableArray; + /** + *See findHashTableValue(); -Dean + */ + private int hashTableArraySize; + /** + *See findHashTableValue(); -Dean + */ + private int hashValue; + /** + *Returns the Big O notation for the HashTable. + *@return String + */ + private String bigONotation() { + String bigO = "The Big O notation for HashTable is O(1)"; + return bigO; + } + private void createHashTable(int n) { + hashTable = new HashTable(n); + hashTableArray = hashTable.containerArray; + } + /** + * Method for searching the hashTable. -Dean + */ + private int findHashTableValue() { + hashFinder = new HashFinder(); + + hashValue = hashTableArray[10]; + System.out.println("The hash value to be retrieved is: " + hashValue); + int valueIndex = hashFinder.findHashValue(hashValue, hashTableArraySize, hashTableArray); + return valueindex; + } +} diff --git a/production/ClassProject/Middleware/HashFinder.java b/production/ClassProject/Middleware/HashFinder.java new file mode 100644 index 0000000..5c2c3e2 --- /dev/null +++ b/production/ClassProject/Middleware/HashFinder.java @@ -0,0 +1,65 @@ +package edu.oakland.production.GroupProject.Middleware; +/** +*@author Jared Okoniewski, Jesse Rominske, Dean DeHart +*@version version 3.0 150401 +*@since version 1.0 152403 +*/ +public class HashFinder { + /** + *The input variable that will be located within the Hash Table. + */ + private int hashInput; + /** + *The size of the Hash Table being searched. + */ + private int hashSize; + /** + *The reference to the Hash Table itself. + */ + private int[] table; + /** + *The index of wherever the search found the element. + *Used in Display package for index return. + */ + private int hashOutput; + /** + *Finds a value within the Hash Table. + *Accepts an input value, an array size, and an array as arguments. + *@param input The input value, assigned to hashInput. Order needs to be changed? -Dean + *@param size The size value, assigned to hashSize. Order needs to be changed? -Dean + *@param array The array, assigned to table. Order needs to be changed? -Dean + */ + public int findHashValue(int input, int size, int[] array) { + + System.out.println("The method findValue was called."); //announce method + //assigning arguments to variables + hashInput = input; + hashSize = size; + table = array; + int items = 0; + + int arrayIndex = input % (size - 1); //find the original hash key + + while(table[arrayIndex] != -1) { //as long as the slot has something in it + if(table[arrayIndex] == input) { //if we found it + System.out.println(input + "was found at index " + arrayIndex); //tell user + hashOutput = input; //set the output to the value of the input + break; //end the loop + } + ++arrayIndex; //increment the index at each attempt + ++items; //Increment the number of items searched + arrayIndex %= size; //return to table[0] if we can't find it + break; //end the loop + } + if(hashOutput != input) { //if there is a mismatch between input and output + System.out.println("Value not found in hash table."); //tell user + } + + System.out.println(items + " items were searched"); //spit out the number of items searched + + return arrayIndex;//spit out the index of the value found + } +} +/** +*This class is that which finds a value in a Hash Table. +*/ diff --git a/production/ClassProject/Middleware/LinkListDB.java b/production/ClassProject/Middleware/LinkListDB.java new file mode 100644 index 0000000..0bbf3d3 --- /dev/null +++ b/production/ClassProject/Middleware/LinkListDB.java @@ -0,0 +1,24 @@ + +/** +*@author Eldari Gogiashvili +*@version version 1.0.0 date 150331 +*since version 1.0.0 +*/ + +/** +*This class represents the middleware +*/ + +public class LinkListDB{ + + public static add(){ + +} + public static get(){ +} + + public static set(){ +} +/** +*This class was created for Middleware. +*/ \ No newline at end of file diff --git a/production/ClassProject/Middleware/LinkedListDB.java b/production/ClassProject/Middleware/LinkedListDB.java new file mode 100644 index 0000000..d72f126 --- /dev/null +++ b/production/ClassProject/Middleware/LinkedListDB.java @@ -0,0 +1,27 @@ +package edu.oakland.production.ClassProject; + +/** +*@author Eldari Gogiashvili, Zack Waldrup +*@version version 1.0.1 date 150331 +*since version 1.0.0 +*/ + +/** +*This class represents the middleware +*/ + +public class LinkedListDB{ + + public void add(int index, int value){ + } + + public int get(int value){ + return 1; + } + + public void set(int index, int value){ + } +} +/** +*This class was created for Middleware. +*/ \ No newline at end of file diff --git a/production/ClassProject/Middleware/LinkedListMiddleware.java b/production/ClassProject/Middleware/LinkedListMiddleware.java new file mode 100644 index 0000000..7ea4c91 --- /dev/null +++ b/production/ClassProject/Middleware/LinkedListMiddleware.java @@ -0,0 +1,171 @@ +package edu.oakland.production.ClassProject; + +import java.util.*; +import edu.oakland.production.ClassProject.*; + +/** +*@author Zack Waldrup +*@version version 2.4 150403 +*@since version 1.0 150323 +*/ +public class LinkedListMiddleware { + + /** + *Instance variables needed for the constructors and methods + */ + int listSize; + int iMin; + long taskTime; + int value; + static long startTime, endTime; + public boolean valuePresent = false; + LinkedListDB db; + + /** + *Overloaded constructor for the LinkedListMiddleware class. + *Passes the requested list size to the database. + *@param listSize of type "int" + */ + public LinkedListMiddleware(int listSize) { + this.listSize = listSize; + db = new LinkedListDB(); + this.createLinkedList(listSize); + } + + /** + *This method performs a Selection Sort on a LinkedList + *Big O: O(n^2) + */ + public void selectSort() { + startTime = System.currentTimeMillis(); + + for (int j = 0; j < listSize; j++) { + iMin = j; + for (int i = j + 1; i < listSize; i++) { + if (db.get(i) < db.get(iMin)) { + iMin = i; + } + } + if(iMin != j) { + swapValues(j, iMin); + } + } + endTime = System.currentTimeMillis(); + taskTime = endTime - startTime; + System.out.println("Selection Sort time taken: " + taskTime); + } + + /** + *This method performs a Bubble Sort on a LinkedList + *Big O: O(n^2) + */ + public void bubbleSort() { + startTime = System.currentTimeMillis(); + + for (int i = listSize - 1; i > 1; i--) { + for (int j = 0; j < i; j++) { + if(db.get(j) > db.get(j + 1)){ + swapValues(j, j+1); + } + } + } + endTime = System.currentTimeMillis(); + taskTime = endTime - startTime; + System.out.println("Bubble Sort time taken: " + taskTime); + } + + /** + *This method linearly searches a LinkedList + *Big O: O(n) + *@param value of type "int" + */ + public void linearSearch(int value) { + this.value = value; + valuePresent = false; + String indexWithValue = ""; + startTime = System.currentTimeMillis(); + + for (int i = 0; i < listSize; i++) { + if(db.get(i) == value) { + valuePresent = true; + indexWithValue += i + " "; + } + } + System.out.println("Value found: " + valuePresent); + endTime = System.currentTimeMillis(); + taskTime = endTime - startTime; + System.out.println("Linear Search time taken: " + taskTime); + } + + /** + *This method conducts a binary searche on a LinkedList + *Big O: O(log(n)) + *@param value of type "int" + */ + public void binarySearch(int value) { + this.value = value; + int lowIndex = 0; + int highIndex = listSize - 1; + int timesThrough = 0; + startTime = System.currentTimeMillis(); + + while (lowIndex <= highIndex) { + int middleIndex = (highIndex + lowIndex) / 2; + if(db.get(middleIndex) < value) { + lowIndex = middleIndex + 1; + } else if(db.get(middleIndex) > value) { + highIndex = middleIndex - 1; + } else if(db.get(middleIndex) == value){ + valuePresent = true; + System.out.println("Found " + value + "at " + middleIndex); + lowIndex = highIndex + 1; + } else { + System.out.println("Value is not in this list"); + } + timesThrough++; + } + + endTime = System.currentTimeMillis(); + taskTime = endTime - startTime; + System.out.println("Binary Search time taken: " + taskTime); + System.out.println("Binary Search times through: " + timesThrough); + } + + /** + *This method swaps the values of 2 elements in a LinkedList + *@param indexOne of type "int" + *@param indexTwo of type "int" + */ + public void swapValues(int indexOne, int indexTwo) { + int temp = db.get(indexOne); + db.set(indexOne,db.get(indexTwo)); + db.set(indexTwo, temp); + } + + /** + *Method for creating a LinkedList + *@param listSize of type "int" + *@return list1 of type "LinkedList" + */ + public void createLinkedList(int listSize) { + this.listSize = listSize; + + for(int i = 0; i < listSize; i++) { + db.add(randomInt(100, 1000)); + } + } + + /** + *This method gives a random number based on a maximum and + *minimum range of selection + *@param min of type "int" + *@param max of type "int" + *@return randomNumber of type "int" + */ + public static int randomInt(int min, int max) { + Random rand = new Random(); + int randomNumber = rand.nextInt((max - min) + 1) + min; + return randomNumber; + } + +} \ No newline at end of file diff --git a/production/ClassProject/Middleware/MidArrayList.java b/production/ClassProject/Middleware/MidArrayList.java new file mode 100644 index 0000000..6839275 --- /dev/null +++ b/production/ClassProject/Middleware/MidArrayList.java @@ -0,0 +1,197 @@ +package edu.oakland.production.ClassProject; + +import java.util.ArrayList; +import edu.oakland.production.ClassProject.*; + +/** +*@author Toufiq Hussain +*@version version 1.3 150330 +*@since version 1.0 150323 +**/ +public class MidArrayList { + + /** + *Declared instance variables here. + */ + private ArrayListDatabase theArray; + private int arraySize; + static long startTime; + static long endTime; + + /** + *Overloaded constructor to create database. Takes in + *a variable of type "int" to specify size. + */ + MidArrayList(int size){ + arraySize =size; + theArray = new ArrayListDatabase(size); + } + + /** + *Generates a random array to fill database. + */ + public void generateRandomArray() { + System.out.println("Generating random array..."); + for (int i = 0; i < arraySize; i++) { + int j = 0; + j = (int) ((Math.random() * 1000) + 100); + theArray.addStudent(j); + } + } + + /** + *Returns the size of the array as a String sentence + */ + public int returnArraySize(){ + return theArray.returnSize(); + } + + /** + *Returns the array in its entirety. USE ONLY WHEN DEBUGGING + */ + public void returnArray(){ + + for(int i = 0; i 1; i--) { + for (int j = 0; j < i; j++) { + if (theArray.getStudent(j) > theArray.getStudent(j + 1)) { + swapValues(j, j + 1); + } + } + } + + endTime = System.currentTimeMillis(); + System.out.println("Bubble sort took " + (endTime - startTime) + " ms"); + } + + /** + *Selection sorts the entire array and prints the time taken. + */ + public void selectionSort(){ + System.out.println("Selection sort initialized"); + startTime = System.currentTimeMillis(); + + int min = 0; + for(int j=0;j < arraySize-1; j++){ + min = j; + + for(int i = j+1; i < arraySize;i++){ + if(theArray.getStudent(i) < theArray.getStudent(min)){ + min = i; + } + } + + if(min != j){ + swapValues(j,min); + } + } + + endTime = System.currentTimeMillis(); + System.out.println("Selection sort took " + (endTime - startTime) + " ms"); + } + + /** + *Binary searches for a value in a sorted array. + *This takes an int (the value to search for). + */ + public void binarySearch(int value) { + + System.out.println("Binary search initialized."); + + startTime = System.currentTimeMillis(); + + int lowIndex = 0; + int highIndex = arraySize - 1; + + int timesThrough = 0; + + while (lowIndex <= highIndex) { + + int middleIndex = (highIndex + lowIndex) / 2; + + if (theArray.getStudent(middleIndex) < value) + lowIndex = middleIndex + 1; + + else if (theArray.getStudent(middleIndex) > value) + highIndex = middleIndex - 1; + + else { + + System.out.println("Found a match for " + value + " at index " + middleIndex); + + lowIndex = highIndex + 1; + + } + + timesThrough++; + + } + + endTime = System.currentTimeMillis(); + + System.out.println("Binary search took " + (endTime - startTime) + " ms"); + + System.out.println("Times through: " + timesThrough); + + } + + /** + *Linear searches for a value in a sorted array. + *This takes an int (the value to search for). + */ + public void linearSearch(int value) { + + boolean valueInArray = false; + String indexsWithValue = ""; + + System.out.println("Linear search initialized"); + startTime = System.currentTimeMillis(); + + for (int i = 0; i < arraySize; i++) { + + if (theArray.getStudent(i) == value) { + valueInArray = true; + indexsWithValue += i + " "; + } + + } + + //System.out.println(indexsWithValue); + System.out.println("Value found: " + valueInArray); + + endTime = System.currentTimeMillis(); + + System.out.println("Linear search took " + (endTime - startTime) + " ms"); + + } +} \ No newline at end of file diff --git a/production/ClassProject/Middleware/Middleware methods.docx b/production/ClassProject/Middleware/Middleware methods.docx new file mode 100644 index 0000000..586c568 Binary files /dev/null and b/production/ClassProject/Middleware/Middleware methods.docx differ diff --git a/production/ClassProject/Middleware/Middleware.java b/production/ClassProject/Middleware/Middleware.java new file mode 100644 index 0000000..c564b51 --- /dev/null +++ b/production/ClassProject/Middleware/Middleware.java @@ -0,0 +1,189 @@ +package edu.oakland.production.ClassProject.middleware; +import edu.oakland.production.ClassProject.middleware.*; +/** +*@author Eldari Gogiashvili +*@version version 2.0.0 date 150405 +*since version 1.0.0 date 150331 +*/ + +/** +*This class represents the middleware. +*/ + +public class Middleware { + + /** + *Instance variables used in subsequent methods. + */ + int ListSize; + int Size; + int size; + int key1; + int key2; + int key3; + int n; + int input; + int size; + int array; + int param; + int ID; + string Name; + string Major; + double GPA; + double TG; + + LinkedListMiddleware mw = new LinkedListMiddleware(); + MidArrayList mw1 = new MidArrayList(); + BinaryTreeMW mw2 = new BinaryTreeMW(); + HashClient mw3 = new HashClient(); + HashFinder mw4 = new HashFinder(); + StackCut mw5 = new StackCut(); + StudentStack studentStack = new StudentStack(10); + /** + *Constructor for LinkedListMiddleware. + *@param ListSize Takes an integer and passes it to the LinkedListMiddleware instance. + *Calls the LinkedListMiddleware, selectSort, bubbleSort,linearSearch, and binarySearch methods. + */ + public void llMW(){ + mw.LinkedListMiddleware(int ListSize); + } + public void selectSortLL(){ + mw.selectSort(); + return int TaskTime + } + public void bubbleSortLL(){ + mw.bubbleSort(); + return int TaskTime + } + public void linearSearchLL(){ + mw.linearSearch(); + return int TaskTime + } + public String binarySearchLL(){ + mw.binarySearch(); + return int TaskTime +" "+ int TimesThrough + } + + /** + *Constructor for MidArrayList. + *@param Size Takes an integer and passes it to the MidArrayList instance. + *Calls the MidArrayList, bubbleSort, selectionSort, linearSearch, and binarySearch methods. + */ + public void alMW(){ + mw1.MidArrayList(int Size); + } + public void bubbleSortAL(){ + mw1.bubbleSort(); + return int TaskTime + } + public void selectionSortAL(){ + mw1.selectionSort(); + return int TaskTime + } + public void linearSearchAL(){ + mw1.linearSearch(); + return int TaskTime + } + public String binarySearchAL(){ + mw1.binarySearch(); + return int TaskTime +" "+ int TimesThrough + } + + /** + *Constructor for BinaryTree. + *@param size Takes an integer and passes it to the BinaryTree instance. + *@param key1 Passes random string value to the BinaryTree instance. + *@param key2 Passes random string value to the BniaryTree instance. + *@param key3 Passes random string value to the BinaryTree instance. + *Calls the createBinaryTree, calculatePreorderNodesSearched, calculateInOrderNodesSearched, calculatePreorderSearchDuration, calculateInOrderSearchDuration, calculateBigORelationship, getDatabase, and setDatabase methods. + */ + public void BinaryTreeMW(){ + mw2.BinaryTreeMW(int size); + } + public String calculatePreorderNodesSearched() { + return mw2.calculatePreorderNodesSearched(int key1, int key2, int key3); + } + public String calculateInOrderNodesSearched() { + return mw2.calculateInOrderNodesSearched(int key1, int key2, int key3); + + } + public String calculatePreorderSearchDuration() { + return mw2.calculatePreorderSearchDuration(int key1, int key2, int key3); + } + public String calculateInOrderSearchDuration() { + return mw2.calculateInOrderSearchDuration(int key1, int key2, int key3); + } + + public String calculateBigORelationship() { + return mw2.calculateBigORelationship(); + } + + /** + *Constructor for HashClient. + *@param n Takes an integer and passes it to the HashClient instance. + *Calls the createHashTable, findHashTableValue, and BigONotation methods. + */ + public void createHashTable(){ + mw3.createHashTable(int n); + } + public int findHashTableValue(int value){ + return mw3.findHashTableValue(int value); + } + public String bigONotation() { + return mw3.bigONotation(); + } + /** + *Constructor for HashFinder. + *@param input Passes integer to the HashFinder instance. + *@param size Passes integer to the HashFinder instance. + *@param array Passes array to the HashFinder instance. + *@return the location of the value + */ + public int findHashValue(){ + return mw4.findHashValue(int input, int size, int array); + } + + /** + *Constructor for StackCut. + *@param param Passes a parameter to the StackCut instance. + */ + public void StackCut() { + mw5.StackCut(int param); + } + public String displayStacks(){ + return mw5.displayStacks(); + } + public String peek(){ + return mw5.peek().toString(); + } + + /** + *Method for creating a Student. + *@param ID + *@param Name + *@param Major + *@param GPA + *@param TG + *Creates a Student Object and pushes it to the stack. + */ + public void createStudent(int ID, string Name, string Major, double GPA, double TG) { + Student newStudent = new Student(ID, Name, Major, GPA, TG); + studentStack.push(newStudent); + } + + /** + * This method cuts the list of students down to size + */ + public String[] cutStudents() { + studentStack.cut(5); + } + + /** + * This method will return an array of Who got Scholarships + */ + public String[] getScholarships() { + } +} +/** +*This class was created for Middleware. +*/ diff --git a/production/ClassProject/Middleware/Middleware_1_B.java b/production/ClassProject/Middleware/Middleware_1_B.java new file mode 100644 index 0000000..e48ceef --- /dev/null +++ b/production/ClassProject/Middleware/Middleware_1_B.java @@ -0,0 +1,426 @@ +package edu.oakland.production.ClassProject.Middleware; + +//Import java util framework +import java.util.*; + +//Import Middleware stuff. +import edu.oakland.production.ClassProject.Middleware.*; + +//Import BinaryTree.java +import edu.oakland.production.ClassProject.Database.*; + + +/* + * Middleware Part 1B. Purpose is to experiment with BinaryTrees'. + * + * @author Joshua Herkness, Trevor Luebbert Middleware + * @version version 1.1 + * @since version 1.0 + */ +public class Middleware { + + /// Minimum possible key value, used with generating a random key. + private int minimumKeyValue = 400000; + /// Maximum possible key value, used with generating a random key. + private int maximumKeyValue = 800000; + + /// Minimum possible name value, used with generating a random name. + private int minimumNameValue = 200000; + /// Maximum possible key value, used with generating a random name. + private int maximumNameValue = 600000; + + Database database; + + /* + * Default constructor for the Middleware Class. + * + * @param database Database object. + * + * @returns Middleware + */ + public Middleware(Database database){ + + //Link the database + this.database = database + } + + /* + * Creates a binary tree inside the database given a size, then populates it with non-duplicate random integer and string values. + * + * @param size Integer value corresponding to the size of the binary tree. + */ + public void createBinaryTree(int size){ + + database.createBinaryTree(size); + + BinaryTree binaryTree = database.getBinaryTree(); + + populateBinaryTree(binaryTree, size); + } + + /* + * Populates a BinaryTree object with a given size, with a key and + * name for each node with a non-duplicate random number. + * + * @param binaryTree BinaryTree object, located within the database. + * @param size Integer value corresponding to the size of the binary tree. + * + */ + private void populateBinaryTree(BinaryTree binaryTree, int size){ + + binaryTree = new BinaryTree(); + + // Create a non-duplicate random number list for keys. + List nonDuplicateRandomNumberKeys = new List(); + // Create a non-duplicate random number list for names. + List nonDuplicateRandomNumberNames = new List(); + + // Populate both key and name lists. + nonDuplicateRandomNumberKeys = nonDuplicateRandomNumbers(minimumKeyValue, maximumKeyValue, size); + nonDuplicateRandomNumberNames = nonDuplicateRandomNumbers(minimumNameValue, maximumNameValue, size); + + for (int i = 0; i < size; i++){ + + // Reference key integer from a given index. + int key = nonDuplicateRandomNumberKeys.get(i); + // Reference name integer from a given index, then convert to a string. + String name = Integer.toString(nonDuplicateRandomNumberNames.get(i)); + + // Add a node to the BinaryTree, given the key and name. + binaryTree.addNode(key, name); + + } + } + + /* + * Searches for three integer key values, and provide a record of the amount of nodes searched through, durring a preorder search, for each key searched. + * + * @param key1 Integer value corresponding to a key value. + * @param key2 Integer value corresponding to a key value. + * @param key3 Integer value corresponding to a key value. + * + * @returns nodesSearched String value corresponding to the number of nodes searched respectively. + */ + public String calculatePreorderNodesSearched(int key1, int key2, int key3){ + + String nodesSearched = ""; + + BinaryTree binaryTree = this.database.getBinaryTree(); + Node focusNode = binaryTree.getRootNode(); + + nodesSearched += Integer.toString(calculatePreorderNodesSearched(binaryTree, focusNode, key1)); + nodesSearched += " "; + + nodesSearched += Integer.toString(calculatePreorderNodesSearched(binaryTree, focusNode, key2)); + nodesSearched += " "; + + nodesSearched += Integer.toString(calculatePreorderNodesSearched(binaryTree, focusNode, key3)); + + return nodesSearched; + } + + /* + * Searches for three integer key values, and provide a record of the amount of nodes searched through, durring a in order search, for each key searched. + * + * @param key1 Integer value corresponding to a key value. + * @param key2 Integer value corresponding to a key value. + * @param key3 Integer value corresponding to a key value. + * + * @returns nodesSearched String value corresponding to the number of nodes searched respectively. + */ + public String calculateInOrderNodesSearched(int key1, int key2, int key3){ + + String nodesSearched = ""; + + BinaryTree binaryTree = this.database.getBinaryTree(); + Node focusNode = binaryTree.getRootNode(); + + nodesSearched += Integer.toString(calculateInOrderNodesSearched(binaryTree, focusNode, key1)); + nodesSearched += " "; + + nodesSearched += Integer.toString(calculateInOrderNodesSearched(binaryTree, focusNode, key2)); + nodesSearched += " "; + + nodesSearched += Integer.toString(calculateInOrderNodesSearched(binaryTree, focusNode, key3)); + + return nodesSearched; + } + + /* + * Calculates the amount of nodes searched in a preorder search, for locating a given key. + * + * @param binaryTree BinaryTree object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * + * @returns int Integer type corresponding to the number of nodes searched through. + */ + private int calculatePreorderNodesSearched(BinaryTree binaryTree, Node focusNode, int key){ + + int nodesSearched = calculatePreorderNodesSearched(binaryTree, focusNode, key, true); + + return nodesSearched; + + } + + /* + * Helper recursive method used to calculates the amount of nodes searched in a preorder search, for locating a given key. + * + * @param binaryTree BinaryTree object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * @param continueSearch Boolean value corresponding to whether the node has been located. + * + * @returns int Integer type corresponding to the number of nodes searched through. + */ + private int calculatePreorderNodesSearched(BinaryTree binaryTree, Node focusNode, int key, boolean continueSearching){ + + // Begin each recursion with zero nodes searched. + int nodesSearched = 0; + + // Ignore the recursion loop if the node is already found, or if the node is non existant. + if (!continueSearching){ + return 0; + } else if (focusNode == null){ + return 0; + } else { + // Count the node. + nodesSearched++; + } + + // If the focus node has the desired key, increament the amount of nodesSearched, and + if (focusNode.getKey() == key){ + + continueSearching = false; + return nodesSearched; + + } + + if (focusNode.leftNode != null){ + nodesSearched += calculatePreorderNodesSearched(binaryTree, focusNode.leftNode, key, continueSearching); + } + + if (focusNode.rightNode != null){ + nodesSearched += calculatePreorderNodesSearched(binaryTree, focusNode.righNode, key, continueSearching); + } + + return nodesSearched; + + } + + /* + * Calculates the amount of nodes searched in an in order search, for locating a given key. + * + * @param binaryTree BinaryTree object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * + * @returns int Integer type corresponding to the number of nodes searched through. + */ + private int calculateInOrderNodesSearched(BinaryTree binaryTree, Node focusNode, String name){ + + int nodesSearched = calculateInOrderNodesSearched(binaryTree, focusNode, key, true); + + return nodesSearched; + } + + /* + * Helper recursive method used to calculates the amount of nodes searched in an in order search, for locating a given key. + * + * @param binaryTree BinaryTree object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * @param continueSearch Boolean value corresponding to whether the node has been located. + * + * @returns int Integer type corresponding to the number of nodes searched through. + */ + private int calculateInOrderNodesSearched(BinaryTree binaryTree, Node focusNode, String name, boolean continueSearching){ + + // Begin each recursion with zero nodes searched. + int nodesSearched = 0; + + // Ignore the recursion loop if the node is already found, or if the node is non existant. + if (!continueSearching){ + return 0; + } else if (focusNode == null){ + return 0; + } else { + // Count the node. + nodesSearched++; + } + + if (focusNode.leftNode != null){ + nodesSearched += calculateInOrderNodesSearched(binaryTree, focusNode.leftNode, key, continueSearching); + } + + // If the focus node has the desired key, increament the amount of nodesSearched, and + if (focusNode.getKey() == key){ + + continueSearching = false; + return nodesSearched; + + } + + if (focusNode.rightNode != null){ + nodesSearched += calculateInOrderNodesSearched(binaryTree, focusNode.righNode, key, continueSearching); + } + + return nodesSearched; + } + + /* + * Calculates the amount of time (in milliseconds) needed to conduct a preorder search on three given keys. + * + * @param key1 Integer value corresponding to a key value. + * @param key2 Integer value corresponding to a key value. + * @param key3 Integer value corresponding to a key value. + * + * @returns duration String value corresponding to the time elapsed durring the searches. + */ + public String calculatePreorderSearchDuration(int key1, int key2, int key3){ + + String duration = ""; + + BinaryTree binaryTree = this.database.getBinaryTree(); + Node focusNode = binaryTree.getRootNode(); + + duration += Double.toString(calculatePreorderSearchDuration(binaryTree, focusNode, key1)); + duration += " "; + + duration += Double.toString(calculatePreorderSearchDuration(binaryTree, focusNode, key2)); + duration += " "; + + duration += Double.toString(calculatePreorderSearchDuration(binaryTree, focusNode, key3)); + + return duration; + } + + /* + * Calculates the amount of time (in milliseconds) needed to conduct a preorder search on three given keys. + * + * @param key1 Integer value corresponding to a key value. + * @param key2 Integer value corresponding to a key value. + * @param key3 Integer value corresponding to a key value. + * + * @returns duration String value corresponding to the time elapsed durring the searches. + */ + public String calculateInOrderSearchDuration(int key1, int key2, int key3){ + + String duration = ""; + + BinaryTree binaryTree = this.database.getBinaryTree(); + Node focusNode = binaryTree.getRootNode(); + + duration += Double.toString(calculateInOrderSearchDuration(binaryTree, focusNode, key1)); + duration += " "; + + duration += Double.toString(calculateInOrderSearchDuration(binaryTree, focusNode, key2)); + duration += " "; + + duration += Double.toString(calculateInOrderSearchDuration(binaryTree, focusNode, key3)); + + return duration; + } + + /* + * Calculates the amount of time (in milliseconds) needed to conduct a preorder search on a given key. + * + * @param binaryTree BinaryTree object. + * @param focusNode Start or begining node of the binary tree. + * @param key Integer value corresponding with desired search value. + * + * @returns double Double type corresponding to time taken to search the binaryTree. + */ + private double calculatePreorderSearchDuration(BinaryTree binaryTree, Node focusNode, int key){ + + double startTime = System.currentTimeMillis(); + int temporary = calculatePreorderNodesSearched(binaryTree, focusNode, key); + double endTime = System.currentTimeMillis(); + + return (endTime - startTime); + } + + /* + * Calculates the amount of time (in milliseconds) needed to conduct an in order search on a given key. + * + * @param binaryTree BinaryTree object. + * @param focusNode Start or begining node of the binary tree. + * @param name String value corresponding with desired search value. + * + * @returns double Double type corresponding to time taken to search the binaryTree. + */ + private double calculateInOrderSearchDuration(BinaryTree binaryTree, Node focusNode, String name){ + + double startTime = System.currentTimeMillis(); + int temporary = calculateInOrderNodesSearched(binaryTree, focusNode, key); + double endTime = System.currentTimeMillis(); + + return (endTime - startTime); + } + + /* + * Description. Not working just yet. + * + * @param binaryTree BinaryTree object. + * + * @returns String String corresponding to the big O relationship for the binary tree. + */ + public String calculateBigORelationship(BinaryTree binaryTree){ + + } + + /* + * Generates a non-duplicate random number list, given a minimumValue, maximumValue, and size. + * + * @param minimumValue Integer value corresponding to the minimum possible random value generated. + * @param maximumValue Integer value corresponding to the maximum possible random value generated. + * + * @returns List List type, shuffled to mimic non-duplicate random numbers. + */ + private List createNonDuplicateRandomNumbers(int minimumValue, int maximumValue, int size){ + + // Create an instance of ArrayList, with type int. + ArrayList nonDuplicateRandomNumbers = new ArrayList(); + + //Test for errors with provided data. If there arent enough possible numbers, return null. + if ((maximumValue - minimumValue) < size){ + + //There has been an error. + return null; + + } + + // For the range of numbers provided. + // Creates an ArrayList of integers from minimumValue to maximumValue. + for (int i = minimumValue; i <= maximumValue; i++){ + + // Add that number to the ArrayList. + nonDuplicateRandomNumbers.add(i); + } + + // Shuffle the ArrayList, randomizing the numbers. + Collections.shuffle(nonDuplicateRandomNumbers); + + // Return a immutable List object, created from the ArrayList, trimming off unnecessary values. + return nonDuplicateRandomNumbers.subList(0, size - 1); + + } + + /* + * Retrieves the database object. + * + * @returns database Database object. + */ + public Database getDatabase(){ + return this.database; + } + + /* + * Modifies the database object stored in Middleware. + * + * @param database Database object corresponding to the new database. + */ + public void setDatabase(Database database){ + this.database = database; + } +} \ No newline at end of file diff --git a/production/ClassProject/Middleware/MockDisplay.java b/production/ClassProject/Middleware/MockDisplay.java new file mode 100644 index 0000000..c167935 --- /dev/null +++ b/production/ClassProject/Middleware/MockDisplay.java @@ -0,0 +1,35 @@ +package edu.oakland.production.ClassProject; + +/** +*@author Eldari Gogiashvili, Zack Waldrup +*@version version 1.0.1 date 150331 +*since version 1.0.0 +*/ + +/** +*This class represents the middleware +*/ + +public class MockDisplay { + + int ListSize = 10; + + /** + *Method for testing the LinkedListMiddleware class + */ + public void testLL(){ + /** + *Constructor for Middleware. + */ + LinkedListMiddleware mw = new LinkedListMiddleware(ListSize); + mw.selectSort(); + mw.linearSearch(100); + mw.binarySearch(100); + + LinkedListMiddleware mw1 = new LinkedListMiddleware(ListSize); + mw1.bubbleSort(); + mw1.linearSearch(100); + mw1.binarySearch(100); + + } +} \ No newline at end of file diff --git a/production/ClassProject/Middleware/Node.java b/production/ClassProject/Middleware/Node.java new file mode 100644 index 0000000..d47c86f --- /dev/null +++ b/production/ClassProject/Middleware/Node.java @@ -0,0 +1,19 @@ +package edu.oakland.production.ClassProject.middleware; + +public class Node{ + + public int tg; + public String name; + public double gpa; + public Node leftChild; + public Node rightChild; + + Node(String stringName, double doubleGpa, int intTg){ + this.name = stringName; + this.gpa = doubleGpa; + this.tg = intTg; + } + public String toString(){ + return name + " has a thesis grade of " + tg; + } +} \ No newline at end of file diff --git a/README.md b/production/ClassProject/Middleware/README.md similarity index 100% rename from README.md rename to production/ClassProject/Middleware/README.md diff --git a/production/ClassProject/Middleware/StackCut.java b/production/ClassProject/Middleware/StackCut.java new file mode 100644 index 0000000..7d4c7a4 --- /dev/null +++ b/production/ClassProject/Middleware/StackCut.java @@ -0,0 +1,57 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.oakland.production.ClassProject.middleware; +import java.util.*; +/** + *@version 1.0 + * @author Sam + */ +public class StackCut extends Stack{ + private int stackSize; + private Object[] stackArray; + private int topOfStack = -1; + + + public StackCut(int param){ + this.stackSize = param; + stackArray = new Object[stackSize]; + } + + public Object push(Object param) { + if(topOfStack+1=0){ + stackArray[topOfStack]=null; + return stackArray[topOfStack--]; + } + else{ + return null; + } + } + + public void displayStacks(){ + for(int n=0; n= 0) + return stackArray[topOfStack]; + else + return null; + } + +} diff --git a/production/ClassProject/Middleware/Student.java b/production/ClassProject/Middleware/Student.java new file mode 100644 index 0000000..d03c464 --- /dev/null +++ b/production/ClassProject/Middleware/Student.java @@ -0,0 +1,35 @@ +package edu.oakland.production.ClassProject.middleware; +import java.util.*; +import edu.oakland.production.ClassProject.middleware.*; +//version 2.0 +public class Student{ + private int gID; + private String name; + private String major; + private double gpa; + private int tg; + + public Student(int gID, String name, String major, double gpa, int tg){ + this.gID = gID; + this.name = name; + this.major = major; + this.gpa = gpa ; + this.tg = tg; + } + public int getID(){ + return gID; + } + public String getName(){ + return name; + } + public String getMajor(){ + return major; + } + public double getGPA(){ + return gpa; + } + + public int getTG(){ + return tg; + } + } \ No newline at end of file diff --git a/test/.DS_Store b/test/.DS_Store new file mode 100644 index 0000000..c25aaeb Binary files /dev/null and b/test/.DS_Store differ diff --git a/test/ClassProject/.DS_Store b/test/ClassProject/.DS_Store new file mode 100644 index 0000000..5251148 Binary files /dev/null and b/test/ClassProject/.DS_Store differ diff --git a/test/ClassProject/Database/TestStack.java b/test/ClassProject/Database/TestStack.java new file mode 100644 index 0000000..a9d1e7b --- /dev/null +++ b/test/ClassProject/Database/TestStack.java @@ -0,0 +1,32 @@ +package edu.oakland.test.ClassProject.Database; + +import edu.oakland.production.ClassProject.Database.*; +import junit.framework.*; +/** + * @version "version 2.0" "20150104" + * @author Sam Bell and Binh Ton + */ +public class TestStack extends TestCase{ + /*private int getID;*/ + private Object firstStudent = 677422; + private Object lastStudent = 177993; + + public void testStack(){ + Student student1 = new Student(677422, "Jones", "IT", 3.82, 95); + Student student2 = new Student(177993, "Smith", "IT", 3.47, 78); + StackCut stackcut = new StackCut(5); + stackcut.push(student1.getID()); + Object compares2 = stackcut.peek(); + assertEquals(firstStudent, compares2); + stackcut.push(student2.getID()); + System.out.println(stackcut.peek()); + stackcut.displayStacks(); + Object compares = stackcut.pop(); + //assertEquals(lastStudent, compares); //this is meant to fail + } + /* + public int getID(){ + return getID; + }*/ + +} \ No newline at end of file diff --git a/test/ClassProject/Database/testBinaryTree.java b/test/ClassProject/Database/testBinaryTree.java new file mode 100644 index 0000000..6e86274 --- /dev/null +++ b/test/ClassProject/Database/testBinaryTree.java @@ -0,0 +1,57 @@ +package edu.oakland.test.ClassProject.Database; + +import edu.oakland.production.ClassProject.Database.*; +import junit.framework.*; + +/** This class utilizes JUnit to test the ATM's ability to verify whether +* sufficient funds are in a bank account prior to withdrawal. +*@author "Bryan Jagielo CSE231" +*@version "1.1" dated 150329 +*@since version 1.0 dated 150329 +*/ +public class testBinaryTree extends TestCase{ + BinaryTreeDB tree; + /** The testAdd() method tests whether the binary tree may add a node to + * the existing set of nodes that it contains + */ + public void testAdd(){ + initTest(); + String name = "Brett"; + int key = 4; + tree.addNode(key,name); + Node foundNode = tree.findNode(key); + String nodeString = foundNode.toString(); + assertTrue(nodeString.equals(name + " has a key " + key)); + } + /** The testRemove() method tests whether the binary tree may remove a + * node from its existing set of nodes. + */ + public void testRemove(){ + initTest(); + String name = "John"; + int key = 1; + tree.remove(key); + Node foundNode = tree.findNode(key); + assertEquals(null,foundNode); + } + /** The testFind() method tests whether the binary tree may find a node + * using a key. + */ + public void testFind(){ + initTest(); + String name = "John"; + int key = 1; + Node foundNode = tree.findNode(key); + String nodeString = foundNode.toString(); + assertTrue(nodeString.equals(name + " has a key " + key)); + } + /** The initTest() method initializes a standard binary tree and + * populates it with nodes in order to prepare the class for each test. + */ + public void initTest(){ + tree = new BinaryTreeDB(); + tree.addNode(0,"Tim"); + tree.addNode(1,"John"); + tree.addNode(2,"Jim"); + } +} diff --git a/test/ClassProject/Middleware/.DS_Store b/test/ClassProject/Middleware/.DS_Store new file mode 100644 index 0000000..795af23 Binary files /dev/null and b/test/ClassProject/Middleware/.DS_Store differ diff --git a/test/ClassProject/Middleware/LLMiddlewareTest.java b/test/ClassProject/Middleware/LLMiddlewareTest.java new file mode 100644 index 0000000..5803d38 --- /dev/null +++ b/test/ClassProject/Middleware/LLMiddlewareTest.java @@ -0,0 +1,76 @@ +package edu.oakland.test.ClassProject; + +import java.util.*; +import junit.framework.*; +import edu.oakland.production.ClassProject.*; + +/** +*@author Zack Waldrup +*@version version 1.1 150403 +*@since version 1.0 150401 +*/ +public class LLMiddlewareTest extends TestCase { + + /** + *Instance variables needed for test classes + */ + int listSize = 10; + int searchInt = 200; + LinkedListMiddleware mw1; + + /** + *setUp method to ensure a new LinkedListMiddleware class on each test + */ + public void setUp() { + mw1 = new LinkedListMiddleware(listSize); + } + + /** + *This method tests whether the elements in the list are in order + */ + public void testSelectSort() { + boolean goodSort = true; + mw1.selectSort(); + for(int i = 1; i < listSize; i++){ + if(mw1.db.get(i) > mw1.db.get(i+1)) { + goodsort = false; + } + } + assertTrue(goodsort); + } + + /** + *This method tests whether the elements in the list are in order + */ + public void testBubbleSort() { + boolean goodSort = true; + mw1.bubbleSort(); + for(int i = 1; i < listSize; i++){ + if(mw1.db.get(i) > mw1.db.get(i+1)) { + goodsort = false; + } + } + assertTrue(goodsort); + } + + /** + *This method tests whether the linear search finds the given integer + */ + public void testLinearSearch() { + mw1.db.add(searchInt); + mw1.selectSort(); + mw1.linearSearch(searchInt); + assertTrue(valuePresent); + } + + /** + *This method tests whether the binary search finds the given integer + */ + public void testBinarySearch() { + mw1.db.add(searchInt); + mw1.selectSort(); + mw1.binarySearch(searchInt); + assertTrue(valuePresent); + } + +} \ No newline at end of file diff --git a/test/ClassProject/Middleware/StudentTest.java b/test/ClassProject/Middleware/StudentTest.java new file mode 100644 index 0000000..220a7d7 --- /dev/null +++ b/test/ClassProject/Middleware/StudentTest.java @@ -0,0 +1,204 @@ +package edu.oakland.production.ClassProject.middleware; +import junit.framework.*; +import edu.oakland.production.ClassProject.middleware.*; +//version 2.2 +public class StudentTest extends TestCase{ + private static Student student1; + private static Student student2; + private static Student student3; + private static Student student4; + private static Student student5; + private static Student student6; + private static Student student7; + private static Student student8; + private static Student student9; + private static Student student10; + + public void setUp(){ + student1 = new Student(677422, "Jones", "IT", 3.82, 95); + student2 = new Student(177993, "Smith", "IT", 3.47, 78); + student3 = new Student(444811, "Breaux", "CS", 3.95, 98); + student4 = new Student(113625, "Brady", "CS", 3.77, 92); + student5 = new Student(382707, "Rominske", "CS", 3.82, 79); + student6 = new Student(447447, "Hardy", "IT", 3.68, 99); + student7 = new Student(661284, "Kominsky", "IT", 3.23, 70); + student8 = new Student(855462, "O'Brien", "IT", 3.44, 85); + student9 = new Student(223344, "Chamberlain", "CS", 3.99, 96); + student10 = new Student(348689, "Grant", "CS", 3.88, 99); + } + + public void testStudent(){ + + final String firstStudentName = "Jones"; + + assertEquals(firstStudentName, student1.getName()); + + final String secondStudentName = "Smith"; + student2 = new Student(177993, "Smith", "IT", 3.47, 78); + assertEquals(secondStudentName, student2.getName()); + + final String thirdStudentName = "Breaux"; + student3 = new Student(444811, "Breaux", "CS", 3.95, 98); + assertEquals(thirdStudentName, student3.getName()); + + final String fourthStudentName = "Brady"; + student4 = new Student(113625, "Brady", "CS", 3.77, 92); + assertEquals(fourthStudentName, student4.getName()); + + final String fifthStudentName = "Rominske"; + student5 = new Student(382707, "Rominske", "CS", 3.82, 79); + assertEquals(fifthStudentName, student5.getName()); + + final String sixthStudentName = "Hardy"; + student6 = new Student(447447, "Hardy", "IT", 3.68, 99); + assertEquals(sixthStudentName, student6.getName()); + + final String seventhStudentName = "Kominsky"; + student7 = new Student(661284, "Kominsky", "IT", 3.23, 70); + assertEquals(seventhStudentName, student7.getName()); + + final String eighthStudentName = "O'Brien"; + student8 = new Student(855462, "O'Brien", "IT", 3.44, 85); + assertEquals(eighthStudentName, student8.getName()); + + final String ninethStudentName = "Chamberlain"; + student9 = new Student(223344, "Chamberlain", "CS", 3.99, 96); + assertEquals(ninethStudentName, student9.getName()); + + final String tenthStudentName = "Grant"; + student10 = new Student(348689, "Grant", "CS", 3.88, 99); + assertEquals(tenthStudentName, student10.getName()); + } + + public void testStack(){ + StackCut stackcut = new StackCut(10); + stackcut.push(student1.getID()); + stackcut.push(student2.getID()); + stackcut.push(student3.getID()); + stackcut.push(student4.getID()); + stackcut.push(student5.getID()); + stackcut.push(student6.getID()); + stackcut.push(student7.getID()); + stackcut.push(student8.getID()); + stackcut.push(student9.getID()); + stackcut.push(student10.getID()); + System.out.println("The current stack is: "); + stackcut.displayStacks(); + System.out.println(); + for(int i=0;i<5;i++){ + Object sgid = stackcut.peek(); + int h = (Integer) sgid; + if(h == student1.getID()){ + System.out.println("Student of name: "+student1.getName()+" and GID: "+student1.getID()+" was removed from the list."); + System.out.println(student1.getName()+" had a major of: "+student1.getMajor()+" a GPA of: "+student1.getGPA()+" and a thesis grade of: "+student1.getTG()); + System.out.println(); + } + if(h == student2.getID()){ + System.out.println("Student of name: "+student2.getName()+" and GID: "+student2.getID()+" was removed from the list."); + System.out.println(student2.getName()+" had a major of: "+student2.getMajor()+" a GPA of: "+student2.getGPA()+" and a thesis grade of: "+student2.getTG()); + System.out.println(); + } + if(h == student3.getID()){ + System.out.println("Student of name: "+student3.getName()+" and GID: "+student3.getID()+" was removed from the list."); + System.out.println(student3.getName()+" had a major of: "+student3.getMajor()+" a GPA of: "+student3.getGPA()+" and a thesis grade of: "+student3.getTG()); + System.out.println(); + } + if(h == student4.getID()){ + System.out.println("Student of name: "+student4.getName()+" and GID: "+student4.getID()+" was removed from the list."); + System.out.println(student4.getName()+" had a major of: "+student4.getMajor()+" a GPA of: "+student4.getGPA()+" and a thesis grade of: "+student4.getTG()); + System.out.println(); + } + if(h == student5.getID()){ + System.out.println("Student of name: "+student5.getName()+" and GID: "+student5.getID()+" was removed from the list."); + System.out.println(student5.getName()+" had a major of: "+student5.getMajor()+" a GPA of: "+student5.getGPA()+" and a thesis grade of: "+student5.getTG()); + System.out.println(); + } + if(h == student6.getID()){ + System.out.println("Student of name: "+student6.getName()+" and GID: "+student6.getID()+" was removed from the list."); + System.out.println(student6.getName()+" had a major of: "+student6.getMajor()+" a GPA of: "+student6.getGPA()+" and a thesis grade of: "+student6.getTG()); + System.out.println(); + } + if(h == student7.getID()){ + System.out.println("Student of name: "+student7.getName()+" and GID: "+student7.getID()+" was removed from the list."); + System.out.println(student7.getName()+" had a major of: "+student7.getMajor()+" a GPA of: "+student7.getGPA()+" and a thesis grade of: "+student7.getTG()); + System.out.println(); + } + if(h == student8.getID()){ + System.out.println("Student of name: "+student8.getName()+" and GID: "+student8.getID()+" was removed from the list."); + System.out.println(student8.getName()+" had a major of: "+student8.getMajor()+" a GPA of: "+student8.getGPA()+" and a thesis grade of: "+student8.getTG()); + System.out.println(); + } + if(h == student9.getID()){ + System.out.println("Student of name: "+student9.getName()+" and GID: "+student9.getID()+" was removed from the list."); + System.out.println(student9.getName()+" had a major of: "+student9.getMajor()+" a GPA of: "+student9.getGPA()+" and a thesis grade of: "+student9.getTG()); + System.out.println(); + } + if(h == student10.getID()){ + System.out.println("Student of name: "+student10.getName()+" and GID: "+student10.getID()+" was removed from the list."); + System.out.println(student10.getName()+" had a major of: "+student10.getMajor()+" a GPA of: "+student10.getGPA()+" and a thesis grade of: "+student10.getTG()); + System.out.println(); + } + stackcut.pop(); + + + } + System.out.println(); + System.out.println("The stack after the cut is: "); + stackcut.displayStacks(); + System.out.println(); + Object unluckystudentone =stackcut.peek(); + stackcut.pop(); + Object unluckystudenttwo = stackcut.peek(); + stackcut.pop(); + System.out.println("The stack after the cut is: "); + stackcut.displayStacks(); + System.out.println(); + System.out.println("The student with GID: "+unluckystudentone+" did not receive the scholarship."); + System.out.println("The student with GID: "+unluckystudenttwo+" also did not receive the scholarship."); + + + Object sgid = stackcut.peek(); + System.out.println(); + System.out.println("The Student with GID: " + sgid + " received the Scholarship."); + assertEquals(sgid , 444811); + stackcut.pop(); + + sgid = stackcut.peek(); + System.out.println("The Student with GID: " + sgid + " received the Scholarship."); + assertEquals(sgid, 177993); + stackcut.pop(); + + sgid = stackcut.peek(); + System.out.println("The Student with GID: " + sgid + " received the Scholarship."); + assertEquals(sgid, 677422); + stackcut.pop(); + } + public void testTree(){ + BinaryTree tree = new BinaryTree(); + + System.out.println(); + tree.addNode(student1.getName(),student1.getGPA(),student1.getTG()); + tree.addNode(student2.getName(),student2.getGPA(),student2.getTG()); + tree.addNode(student3.getName(),student3.getGPA(),student3.getTG()); + tree.addNode(student4.getName(),student4.getGPA(),student4.getTG()); + tree.addNode(student5.getName(),student5.getGPA(),student5.getTG()); + tree.addNode(student6.getName(),student6.getGPA(),student6.getTG()); + tree.addNode(student7.getName(),student7.getGPA(),student7.getTG()); + tree.addNode(student8.getName(),student8.getGPA(),student8.getTG()); + tree.addNode(student9.getName(),student9.getGPA(),student9.getTG()); + tree.addNode(student10.getName(),student10.getGPA(),student10.getTG()); + + tree.preorderTraverseTree(tree.root); + System.out.println(); + System.out.println("Students with a tg of less than 90"); + System.out.println(tree.findNode(90)); + + System.out.println(); + + } +} + + + + +