From c32bb7b7930db10c7d4095a3842eb7003b0777f9 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Tue, 24 Oct 2017 17:07:54 -0400
Subject: [PATCH] Add basic setup for overall program

---
 a2/src/edu/wmich/cs3310/a2/Controller.java | 318 +++++++++++++++++++++
 1 file changed, 318 insertions(+)

diff --git a/a2/src/edu/wmich/cs3310/a2/Controller.java b/a2/src/edu/wmich/cs3310/a2/Controller.java
index db06e5d..c372e44 100644
--- a/a2/src/edu/wmich/cs3310/a2/Controller.java
+++ b/a2/src/edu/wmich/cs3310/a2/Controller.java
@@ -1,4 +1,322 @@
 package edu.wmich.cs3310.a2;
 
+import java.util.Random;
+import java.util.Scanner;
+
+import edu.wmich.cs3310.a2.DataStructures.CharNode;
+import edu.wmich.cs3310.a2.DataStructures.CharQueue;
+
+
+/**
+ * Controller of the program.
+ * Handles all user input/output, and calling of other project classes.
+ */
 public class Controller {
+
+    //region Variables
+
+    private int charNumber;
+    private String nameString;
+    private Random random = new Random();
+    private Scanner reader = new Scanner(System.in);
+    char[] bubbleArray;
+    char[] selectArray;
+    char[] mergeArray;
+    char[] insertArray;
+    char[] bInsertArray;
+    CharQueue bubbleList = new CharQueue();
+    CharQueue selectList = new CharQueue();
+    CharQueue mergeList = new CharQueue();
+    CharQueue insertList = new CharQueue();
+    CharQueue bInsertList = new CharQueue();
+
+    //endregion Variables
+
+
+
+    //region Constructors
+
+    /**
+     * Base constructor.
+     */
+    public Controller() {
+        boolean validInput = false;
+        String tempString;
+
+        // Loop until valid input.
+        while (!validInput) {
+            tempString = GetUserInput("Number of Characters: ");
+            try {
+                charNumber = Integer.parseInt(tempString);
+                validInput = true;
+            } catch (Exception e) {
+                System.out.println("Invalid integer.");
+            }
+        }
+
+        // Get name to modify search with.
+        nameString = GetUserInput("Enter a name: ");
+
+        PopulateData();
+        SortAllDataStructures();
+        PrintAllDataStructures();
+    }
+
+    //endregion Constructors
+
+
+
+    //region Methods
+
+    /**
+     * Populate arrays and linked lists, based on user input.
+     */
+    protected void PopulateData() {
+        int index = 0;
+        int randomInt;
+        CharNode tempNode;
+        CharQueue tempQueue = new CharQueue();
+
+        // Initialize arrays.
+        bubbleArray = new char[charNumber];
+        selectArray = new char[charNumber];
+        mergeArray = new char[charNumber];
+        insertArray = new char[charNumber];
+        bInsertArray = new char[charNumber];
+
+        // Create initial unsorted list.
+        while (index < charNumber) {
+            randomInt = random.nextInt(26);
+            randomInt = randomInt + 97; // Set to valid ascii codes.
+            tempQueue.Enqueue((Character.toChars((char) randomInt))[0]);
+            index++;
+        }
+
+        // Take unsorted list and populate all other data structures with.
+        index = 0;
+        while ((tempNode = tempQueue.Dequeue()) != null) {
+            bubbleArray[index] = tempNode.myData();
+            bubbleList.Enqueue(tempNode.myData());
+            selectArray[index] = tempNode.myData();
+            selectList.Enqueue(tempNode.myData());
+            mergeArray[index] = tempNode.myData();
+            mergeList.Enqueue(tempNode.myData());
+            insertArray[index] = tempNode.myData();
+            insertList.Enqueue(tempNode.myData());
+            bInsertArray[index] = tempNode.myData();
+            bInsertList.Enqueue(tempNode.myData());
+            index++;
+        }
+    }
+
+    //region Sorting Methods
+
+    /**
+     * Calls sorting on all available data structures.
+     */
+    protected void SortAllDataStructures() {
+        ArrayBubbleSort();
+        ListBubbleSort();
+        ArraySelectionSort();
+        ListSelectionSort();
+        ArrayMergeSort();
+        ListMergeSort();
+        ArrayInsertionSort();
+        ListInsertionSort();
+        ArrayBinaryInsertionSort();
+        ListBinaryInsertionSort();
+    }
+
+    protected void ArrayBubbleSort() {
+
+    }
+
+
+    protected void ListBubbleSort() {
+
+    }
+
+
+    protected void ArraySelectionSort() {
+
+    }
+
+
+    protected void ListSelectionSort() {
+
+    }
+
+
+    protected void ArrayMergeSort() {
+
+    }
+
+
+    protected void ListMergeSort() {
+
+    }
+
+
+    protected void ArrayInsertionSort() {
+
+    }
+
+
+    protected void ListInsertionSort() {
+
+    }
+
+
+    protected void ArrayBinaryInsertionSort() {
+
+    }
+    
+
+    protected void ListBinaryInsertionSort() {
+
+    }
+
+    //endregion Sorting Methods
+
+
+
+    //region User Interface Methods
+
+    /**
+     * Acquire user input.
+     * @return String of user's input.
+     */
+    protected String GetUserInput() {
+        String tempString;
+
+        System.out.print("$ ");
+        tempString = reader.next().trim();
+        System.out.println();
+
+        return tempString;
+    }
+
+
+    /**
+     * Prompt for and acquire user input.
+     * @param promptString String to show user.
+     * @return String of user's input.
+     */
+    protected String GetUserInput(String promptString) {
+        String tempString;
+
+        System.out.print(promptString);
+        tempString = reader.next().trim();
+        System.out.println();
+
+        return tempString;
+    }
+
+
+    /**
+     * Prints out values of all available data structures.
+     */
+    protected void PrintAllDataStructures() {
+        int index;
+        CharNode tempNode;
+
+        System.out.println();
+
+        // Bubble.
+        index = 0;
+        tempNode = bubbleList.headNode();
+        System.out.println("Bubble Sorts:");
+        System.out.print("Array: ");
+        while (index < charNumber) {
+            System.out.print(" " + bubbleArray[index]);
+            index++;
+        }
+        System.out.println();
+        System.out.print("List:  ");
+        while (tempNode != null) {
+            System.out.print(" " + tempNode.myData());
+            tempNode = tempNode.nextNode();
+        }
+        System.out.println();
+        System.out.println();
+
+        // Selection.
+        index = 0;
+        tempNode = selectList.headNode();
+        System.out.println("Selection Sorts:");
+        System.out.print("Array: ");
+        while (index < charNumber) {
+            System.out.print(" " + selectArray[index]);
+            index++;
+        }
+        System.out.println();
+        System.out.print("List:  ");
+        while (tempNode != null) {
+            System.out.print(" " + tempNode.myData());
+            tempNode = tempNode.nextNode();
+        }
+        System.out.println();
+        System.out.println();
+
+        // Merge.
+        index = 0;
+        tempNode = mergeList.headNode();
+        System.out.println("Merge Sorts:");
+        System.out.print("Array: ");
+        while (index < charNumber) {
+            System.out.print(" " + mergeArray[index]);
+            index++;
+        }
+        System.out.println();
+        System.out.print("List:  ");
+        while (tempNode != null) {
+            System.out.print(" " + tempNode.myData());
+            tempNode = tempNode.nextNode();
+        }
+        System.out.println();
+        System.out.println();
+
+        // Insertion.
+        index = 0;
+        tempNode = insertList.headNode();
+        System.out.println("Insertion Sorts:");
+        System.out.print("Array: ");
+        while (index < charNumber) {
+            System.out.print(" " + insertArray[index]);
+            index++;
+        }
+        System.out.println();
+        System.out.print("List:  ");
+        while (tempNode != null) {
+            System.out.print(" " + tempNode.myData());
+            tempNode = tempNode.nextNode();
+        }
+        System.out.println();
+        System.out.println();
+
+        // Binary Insertion.
+        index = 0;
+        tempNode = bInsertList.headNode();
+        System.out.println("Binary Insertion Sorts:");
+        System.out.print("Array: ");
+        while (index < charNumber) {
+            System.out.print(" " + bInsertArray[index]);
+            index++;
+        }
+        System.out.println();
+        System.out.print("List:  ");
+        while (tempNode != null) {
+            System.out.print(" " + tempNode.myData());
+            tempNode = tempNode.nextNode();
+        }
+        System.out.println();
+        System.out.println();
+
+        System.out.println();
+    }
+
+    //endregion User Interface Methods
+
+
+    //endregion
 }
-- 
GitLab