diff --git a/.gitignore b/.gitignore index 024a744..f39916b 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ /Assignments/lab15_CalebFontenot/dist/ /Assignments/Experiments/mavenproject1/target/ /Assignments/lab16_arrays2_CalebFontenot/target/ +/Assignments/lab17_CalebFontenot/target/ diff --git a/Assignments/MP5_CalebFontenot/Screenshot 2022-11-22 at 10-56-08 mp5-f22.png b/Assignments/MP5_CalebFontenot/Screenshot 2022-11-22 at 10-56-08 mp5-f22.png new file mode 100644 index 0000000..8964ae1 Binary files /dev/null and b/Assignments/MP5_CalebFontenot/Screenshot 2022-11-22 at 10-56-08 mp5-f22.png differ diff --git a/Assignments/MP5_CalebFontenot/pom.xml b/Assignments/MP5_CalebFontenot/pom.xml new file mode 100644 index 0000000..2c6bb17 --- /dev/null +++ b/Assignments/MP5_CalebFontenot/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot + MP5_CalebFontenot + 1.0-SNAPSHOT + jar + + UTF-8 + 18 + 18 + com.calebfontenot.mp5_calebfontenot.MP5_CalebFontenot + + \ No newline at end of file diff --git a/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.java b/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.java new file mode 100644 index 0000000..6faa4bd --- /dev/null +++ b/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.java @@ -0,0 +1,25 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template + */ + +package com.calebfontenot.mp5_calebfontenot; + +/** + * + * @author caleb + */ +public class MP5_CalebFontenot { + + public static void solveAndPrint(boolean[] ar) { + + } + + public static int[] menu() { + + } + + public static void main(String[] args) { + + } +} diff --git a/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy1.html b/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy1.html new file mode 100644 index 0000000..5b2d801 --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy1.html @@ -0,0 +1,91 @@ + + + +ArraysAndMethodsGames.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethodsGames.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.calebfontenot.lab16_arrays2_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class ArraysAndMethodsGames {
+ public static double min(double[] array) {
+     // pull the first number from the array, and compare that with the numbers in the rest of the array. If that number is less than the number in than the first number, set it to our lowest.
+     double lowest = array[0];
+     for (int i = 1; i < (array.length -1); i++) {
+         lowest = Math.min(lowest, array[i]);
+     }
+     return lowest;
+ }
+    
+    public static double[] readArray() {
+        // Create a double array.
+        int doublesRemaining = 10;
+        double[] returnArray = new double[doublesRemaining];
+        // Create Scanner
+        Scanner input = new Scanner(System.in);
+        // Read characters input and write them to an array.
+        int i = 0;
+        do {
+        System.out.print("Enter 10 doubles (" + doublesRemaining + " left ): ");
+        returnArray[i] = input.nextDouble();
+        i++;
+        doublesRemaining--;
+        } while (doublesRemaining != 0);
+        return returnArray;
+    }
+    
+    /**
+     *
+     * @param array
+     * @return Returns an average of an array.
+     */
+    public static double average(double[] array) {
+        // Iterate through array and add values together into double, then divide by the amount of items in the array.
+        double returnDouble = 0.0;
+        for (double i: array) {
+            returnDouble += i;
+        }
+        returnDouble /= (double) array.length;
+        return returnDouble;
+    }
+    
+    public static void main(String[] args)
+    {
+        double[] doubleArray = new double[10];
+        doubleArray = readArray();
+        System.out.println("average function returns: " + average(doubleArray));
+        System.out.println("lowest function returns: " + min(doubleArray));
+    }
+}
+
+
+ diff --git a/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy2.html b/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy2.html new file mode 100644 index 0000000..f28f2a4 --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy2.html @@ -0,0 +1,56 @@ + + + +ArrayCopy2.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayCopy2.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.calebfontenot.lab16_arrays2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class ArrayCopy2 {
+
+    public static void main(String[] args)
+    {
+        int[] sourceArray = {1, 2, 3, 4, 5};
+        int[] targetArray = new int[sourceArray.length];
+        // Print the source array
+        for (int i = 0; i < sourceArray.length; i++) {
+            System.out.print(sourceArray[i] + " ");
+        }
+        System.out.println();
+        // Copy the source array to the target array in reversed order
+        int j = (sourceArray.length - 1);
+        for (int i = 0; i < sourceArray.length; i++) {
+            targetArray[i] = sourceArray[j];
+            j--;
+        }
+        // Print the target array
+        for (int i = 0; i < sourceArray.length; i++) {
+            System.out.print(targetArray[i] + " ");
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy3.html b/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy3.html new file mode 100644 index 0000000..4c497ce --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy3.html @@ -0,0 +1,52 @@ + + + +ArrayCopy3.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayCopy3.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.calebfontenot.lab16_arrays2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class ArrayCopy3 {
+
+    public static void main(String[] args)
+    {
+        int[] sourceArray = {1, 2, 3, 4, 5};
+        int[] targetArray = new int[sourceArray.length];
+        // Print the source array
+        for (int i = 0; i < sourceArray.length; i++) {
+            System.out.print(sourceArray[i] + " ");
+        }
+        System.out.println();
+        // Copy the source array to the target array
+        System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
+        // Print the target array
+        for (int i = 0; i < sourceArray.length; i++) {
+            System.out.print(targetArray[i] + " ");
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy4.html b/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy4.html new file mode 100644 index 0000000..f8eb5cf --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/ArrayCopy4.html @@ -0,0 +1,66 @@ + + + +ArrayCopy4.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayCopy4.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.calebfontenot.lab16_arrays2_calebfontenot;
+
+import java.util.Arrays;
+
+/**
+ *
+ * @author caleb
+ */
+public class ArrayCopy4 {
+
+    public static void main(String[] args)
+    {
+        int[] array = {1, 2, 3, 4, 5};
+        int[] array1 = Arrays.copyOfRange(array, 2, 5);
+        int[] array2 = new int[array.length - 2];
+        int[] array3 = new int[array.length];
+           System.out.println("array1: (copy with java.util.Arrays.copyOfRange(); )");
+        for (int i: array1) {
+            System.out.print(i + " ");
+        }
+        System.out.println();
+        // Copy array into array2 with a for loop and print it
+        System.out.println("array2: (copy with System.arraycopy(); )");
+        System.arraycopy(array, 2, array2, 0, 3);
+        for (int i : array2) {
+            System.out.print(i + " ");
+        }
+        System.out.println();
+        // Copy array manually
+        System.out.println("array3: (manually copy with for loop)");
+        for (int i : array3) {
+            array[i] = array3[i];
+        }
+        for (int i : array1) {
+            System.out.print(i + " ");
+        }
+        System.out.println();
+    }
+}
+
+
+ diff --git a/Assignments/lab16_arrays2_CalebFontenot/ArrayShift1.html b/Assignments/lab16_arrays2_CalebFontenot/ArrayShift1.html new file mode 100644 index 0000000..e68b9f1 --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/ArrayShift1.html @@ -0,0 +1,54 @@ + + + +ArrayShift1.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayShift1.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.calebfontenot.lab16_arrays2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class ArrayShift1 {
+
+    public static void main(String[] args)
+    {
+        int[] ar = {1, 2, 3, 4, 5};
+        int temp = ar[0];
+        for (int value : ar) {
+            System.out.print(value + " ");
+        }
+        System.out.println();
+
+        for (int i = 1; i < ar.length; ++i) {
+            ar[i - 1] = ar[i];
+        }
+        ar[ar.length - 1] = temp;
+
+        for (int value : ar) {
+            System.out.print(value + " ");
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab16_arrays2_CalebFontenot/ArrayShift2.html b/Assignments/lab16_arrays2_CalebFontenot/ArrayShift2.html new file mode 100644 index 0000000..8a3fb4d --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/ArrayShift2.html @@ -0,0 +1,55 @@ + + + +ArrayShift2.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayShift2.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.calebfontenot.lab16_arrays2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class ArrayShift2 {
+
+    public static void main(String[] args)
+    {
+        int[] ar = {1, 2, 3, 4, 5};
+        int temp = ar[ar.length - 1];
+        
+        for (int value : ar) {
+            System.out.print(value + " ");
+        }
+        System.out.println();
+        
+        for (int i = (ar.length -1); i > 0 ; --i) {
+            ar[i] = ar[i -1];
+        }
+        ar[0] = temp;
+
+        for (int value : ar) {
+            System.out.print(value + " ");
+        }
+    }
+}
+
+
+ diff --git a/Assignments/lab16_arrays2_CalebFontenot/ArraysAndMethods.html b/Assignments/lab16_arrays2_CalebFontenot/ArraysAndMethods.html new file mode 100644 index 0000000..c37a440 --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/ArraysAndMethods.html @@ -0,0 +1,110 @@ + + + +ArraysAndMethods.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethods.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.calebfontenot.lab16_arrays2_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class ArraysAndMethods {
+
+    public static void printArray(int[] arrayInput)
+    {
+        for (int i : arrayInput) {
+            System.out.print(i + " ");
+        }
+        System.out.println();
+    }
+
+    public static void printArray(char[] arrayInput)
+    {
+        for (int i : arrayInput) {
+            System.out.print((char) i + " ");
+        }
+        System.out.println();
+    }
+
+    public static void printArray(double[] arrayInput)
+    {
+        for (double i : arrayInput) {
+            System.out.print(i + " ");
+        }
+        System.out.println();
+    }
+
+    public static int[] reverse(int[] arrayToReverse)
+    {
+        int arrayResult[] = new int[arrayToReverse.length];
+        int j = (arrayToReverse.length - 1);
+        for (int i = 0; i <= arrayToReverse.length - 1; i++) {
+            arrayResult[i] = arrayToReverse[j];
+            j--;
+        }
+        return arrayResult;
+    }
+
+    public static int linearSearch(int list[], int key)
+    {
+        int indexFound = -1;
+        for (int i = 0; i < list.length; ++i) {
+            if (list[i] == key) {
+                indexFound = i;
+            }
+        }
+        return indexFound;
+    }
+
+    public static void main(String[] args)
+    {
+        int[] array = {1, 2, 3, 4, 5};
+        printArray(array);
+        printArray(new int[]{3, 1, 2, 6, 4});
+        printArray(reverse(array));
+
+        System.out.println(linearSearch(array, 5) != 1
+                ? "found at index " + Integer.toString(linearSearch(array, 5))
+                : "not found at index " + Integer.toString(linearSearch(array, 5))
+        );
+        double[] doubles = {6.0, 4.4, 1.9, 2.9, 3.4, 3.5};
+        // Use the built-in sort method to sort the double.
+        java.util.Arrays.sort(doubles);
+
+        char[] chars = {'a', 'A', '4', 'F', 'D', 'P',};
+        //Sort again
+        java.util.Arrays.sort(chars);
+        // Now print the sorted arrays.
+        printArray(doubles);
+        printArray(chars);
+    }
+}
+
+
+ diff --git a/Assignments/lab16_arrays2_CalebFontenot/ArraysAndMethodsGames.html b/Assignments/lab16_arrays2_CalebFontenot/ArraysAndMethodsGames.html new file mode 100644 index 0000000..5b2d801 --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/ArraysAndMethodsGames.html @@ -0,0 +1,91 @@ + + + +ArraysAndMethodsGames.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethodsGames.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.calebfontenot.lab16_arrays2_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class ArraysAndMethodsGames {
+ public static double min(double[] array) {
+     // pull the first number from the array, and compare that with the numbers in the rest of the array. If that number is less than the number in than the first number, set it to our lowest.
+     double lowest = array[0];
+     for (int i = 1; i < (array.length -1); i++) {
+         lowest = Math.min(lowest, array[i]);
+     }
+     return lowest;
+ }
+    
+    public static double[] readArray() {
+        // Create a double array.
+        int doublesRemaining = 10;
+        double[] returnArray = new double[doublesRemaining];
+        // Create Scanner
+        Scanner input = new Scanner(System.in);
+        // Read characters input and write them to an array.
+        int i = 0;
+        do {
+        System.out.print("Enter 10 doubles (" + doublesRemaining + " left ): ");
+        returnArray[i] = input.nextDouble();
+        i++;
+        doublesRemaining--;
+        } while (doublesRemaining != 0);
+        return returnArray;
+    }
+    
+    /**
+     *
+     * @param array
+     * @return Returns an average of an array.
+     */
+    public static double average(double[] array) {
+        // Iterate through array and add values together into double, then divide by the amount of items in the array.
+        double returnDouble = 0.0;
+        for (double i: array) {
+            returnDouble += i;
+        }
+        returnDouble /= (double) array.length;
+        return returnDouble;
+    }
+    
+    public static void main(String[] args)
+    {
+        double[] doubleArray = new double[10];
+        doubleArray = readArray();
+        System.out.println("average function returns: " + average(doubleArray));
+        System.out.println("lowest function returns: " + min(doubleArray));
+    }
+}
+
+
+ diff --git a/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethodsGames.java b/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethodsGames.java new file mode 100644 index 0000000..8dab58b --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethodsGames.java @@ -0,0 +1,62 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package com.calebfontenot.lab16_arrays2_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class ArraysAndMethodsGames { + public static double min(double[] array) { + // pull the first number from the array, and compare that with the numbers in the rest of the array. If that number is less than the number in than the first number, set it to our lowest. + double lowest = array[0]; + for (int i = 1; i < (array.length -1); i++) { + lowest = Math.min(lowest, array[i]); + } + return lowest; + } + + public static double[] readArray() { + // Create a double array. + int doublesRemaining = 10; + double[] returnArray = new double[doublesRemaining]; + // Create Scanner + Scanner input = new Scanner(System.in); + // Read characters input and write them to an array. + int i = 0; + do { + System.out.print("Enter 10 doubles (" + doublesRemaining + " left ): "); + returnArray[i] = input.nextDouble(); + i++; + doublesRemaining--; + } while (doublesRemaining != 0); + return returnArray; + } + + /** + * + * @param array + * @return Returns an average of an array. + */ + public static double average(double[] array) { + // Iterate through array and add values together into double, then divide by the amount of items in the array. + double returnDouble = 0.0; + for (double i: array) { + returnDouble += i; + } + returnDouble /= (double) array.length; + return returnDouble; + } + + public static void main(String[] args) + { + double[] doubleArray = new double[10]; + doubleArray = readArray(); + System.out.println("average function returns: " + average(doubleArray)); + System.out.println("lowest function returns: " + min(doubleArray)); + } +} diff --git a/Assignments/lab17_CalebFontenot/lab17_CalebFontenot.html b/Assignments/lab17_CalebFontenot/lab17_CalebFontenot.html new file mode 100644 index 0000000..ecd1291 --- /dev/null +++ b/Assignments/lab17_CalebFontenot/lab17_CalebFontenot.html @@ -0,0 +1,132 @@ + + + +Lab17_CalebFontenot.java + + + + +
/home/caleb/ASDV-Java/Assignments/lab17_CalebFontenot/src/main/java/com/calebfontenot/lab17_calebfontenot/Lab17_CalebFontenot.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
+ */
+package com.calebfontenot.lab17_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class Lab17_CalebFontenot {
+
+    public static void main(String[] args)
+    {
+        final int NUM_TO_SEARCH_FOR = 2;
+        int[] originalArray = new int[]{420, 41, 7, 2, 26, 2243};
+        System.out.print("Original array: ");
+        printArray(originalArray);
+        selectionSort(originalArray);
+        System.out.print("Sorted array: ");
+        printArray(originalArray);
+
+        System.out.println("Binary Search");
+        System.out.println("-----------------------");
+        System.out.println("binarySearchWhile() returns: " + binarySearchWhile(originalArray, NUM_TO_SEARCH_FOR));
+        isInArray(binarySearchWhile(originalArray, NUM_TO_SEARCH_FOR), NUM_TO_SEARCH_FOR);
+        
+        System.out.println("binarySearchFor() returns: " + binarySearchFor(originalArray, NUM_TO_SEARCH_FOR));
+        isInArray(binarySearchFor(originalArray, NUM_TO_SEARCH_FOR), NUM_TO_SEARCH_FOR);
+
+    }
+
+    public static void isInArray(int arrayResult, int searchQuery)
+    {
+        if (arrayResult == 0) {
+            System.out.println(searchQuery + " is in the array.");
+        } else {
+            System.out.println(searchQuery + " is not in the array.");
+        }
+    }
+
+    public static int[] selectionSort(int[] arr)
+    {
+        // Sort an array by comparing each and every item in the array and swapping them if they are less than the following number
+        for (int i = 0; i < arr.length - 1; ++i) {
+            for (int j = i; j < arr.length; ++j) {
+                if (arr[i] > arr[j]) {
+                    int temp = arr[i];
+                    arr[i] = arr[j];
+                    arr[j] = temp;
+                }
+            }
+        }
+        return arr;
+    }
+
+    public static void printArray(int[] arr)
+    {
+        for (int i : arr) {
+            System.out.print(i + " ");
+        }
+        System.out.println();
+    }
+
+    //replace fors with whiles
+    public static int binarySearchWhile(int[] ar, int key)
+    {
+        int low = 0;
+        int high = ar.length - 1;
+        while (high >= low) {
+            int mid = (low + high) / 2;
+            if (key < ar[mid]) {
+                high = mid - 1;
+            } else if (key == ar[mid]) {
+                return mid;
+            } else {
+                low = mid + 1;
+            }
+        }
+        return 1;
+
+    }
+    //replace while with for
+
+    public static int binarySearchFor(int[] ar, int key)
+    {
+        int low = 0;
+        int high = ar.length - 1;
+        for (low = 0; high >= low;) {
+            int mid = (low + high) / 2;
+            if (key < ar[mid]) {
+                high = mid - 1;
+            } else if (key == ar[mid]) {
+                return mid;
+            } else {
+                low = mid + 1;
+            }
+        }
+        return 1;
+    }
+
+}
+
+
+ diff --git a/Assignments/lab17_CalebFontenot/pom.xml b/Assignments/lab17_CalebFontenot/pom.xml new file mode 100644 index 0000000..9851913 --- /dev/null +++ b/Assignments/lab17_CalebFontenot/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot + lab17_CalebFontenot + 1.0-SNAPSHOT + jar + + UTF-8 + 18 + 18 + com.calebfontenot.lab17_calebfontenot.Lab17_CalebFontenot + + \ No newline at end of file diff --git a/Assignments/lab17_CalebFontenot/src/main/java/com/calebfontenot/lab17_calebfontenot/Lab17_CalebFontenot.java b/Assignments/lab17_CalebFontenot/src/main/java/com/calebfontenot/lab17_calebfontenot/Lab17_CalebFontenot.java new file mode 100644 index 0000000..4a319b0 --- /dev/null +++ b/Assignments/lab17_CalebFontenot/src/main/java/com/calebfontenot/lab17_calebfontenot/Lab17_CalebFontenot.java @@ -0,0 +1,102 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template + */ +package com.calebfontenot.lab17_calebfontenot; + +/** + * + * @author caleb + */ +public class Lab17_CalebFontenot { + + public static void main(String[] args) + { + final int NUM_TO_SEARCH_FOR = 2; + int[] originalArray = new int[]{420, 41, 7, 2, 26, 2243}; + System.out.print("Original array: "); + printArray(originalArray); + selectionSort(originalArray); + System.out.print("Sorted array: "); + printArray(originalArray); + + System.out.println("Binary Search"); + System.out.println("-----------------------"); + System.out.println("binarySearchWhile() returns: " + binarySearchWhile(originalArray, NUM_TO_SEARCH_FOR)); + isInArray(binarySearchWhile(originalArray, NUM_TO_SEARCH_FOR), NUM_TO_SEARCH_FOR); + + System.out.println("binarySearchFor() returns: " + binarySearchFor(originalArray, NUM_TO_SEARCH_FOR)); + isInArray(binarySearchFor(originalArray, NUM_TO_SEARCH_FOR), NUM_TO_SEARCH_FOR); + + } + + public static void isInArray(int arrayResult, int searchQuery) + { + if (arrayResult == 0) { + System.out.println(searchQuery + " is in the array."); + } else { + System.out.println(searchQuery + " is not in the array."); + } + } + + public static int[] selectionSort(int[] arr) + { + // Sort an array by comparing each and every item in the array and swapping them if they are less than the following number + for (int i = 0; i < arr.length - 1; ++i) { + for (int j = i; j < arr.length; ++j) { + if (arr[i] > arr[j]) { + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + } + } + return arr; + } + + public static void printArray(int[] arr) + { + for (int i : arr) { + System.out.print(i + " "); + } + System.out.println(); + } + + //replace fors with whiles + public static int binarySearchWhile(int[] ar, int key) + { + int low = 0; + int high = ar.length - 1; + while (high >= low) { + int mid = (low + high) / 2; + if (key < ar[mid]) { + high = mid - 1; + } else if (key == ar[mid]) { + return mid; + } else { + low = mid + 1; + } + } + return 1; + + } + //replace while with for + + public static int binarySearchFor(int[] ar, int key) + { + int low = 0; + int high = ar.length - 1; + for (low = 0; high >= low;) { + int mid = (low + high) / 2; + if (key < ar[mid]) { + high = mid - 1; + } else if (key == ar[mid]) { + return mid; + } else { + low = mid + 1; + } + } + return 1; + } + +} diff --git a/Assignments/lab6_CalebFontenot/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/Assignments/lab6_CalebFontenot/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst deleted file mode 100644 index 090b0d6..0000000 --- a/Assignments/lab6_CalebFontenot/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1 +0,0 @@ -com/calebfontenot/lab6_calebfontenot/Lab6_CalebFontenot.class diff --git a/Assignments/lab6_CalebFontenot/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/Assignments/lab6_CalebFontenot/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst deleted file mode 100644 index cea5fb2..0000000 --- a/Assignments/lab6_CalebFontenot/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ /dev/null @@ -1 +0,0 @@ -/home/caleb/NetBeansProjects/ADSV Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/Lab6_CalebFontenot.java diff --git a/ZIPs/lab16_arrays2_CalebFontenot.zip b/ZIPs/lab16_arrays2_CalebFontenot.zip new file mode 100644 index 0000000..a87751e Binary files /dev/null and b/ZIPs/lab16_arrays2_CalebFontenot.zip differ diff --git a/ZIPs/lab17_CalebFontenot.zip b/ZIPs/lab17_CalebFontenot.zip new file mode 100644 index 0000000..6d5f3bb Binary files /dev/null and b/ZIPs/lab17_CalebFontenot.zip differ