diff --git a/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java b/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java index 64f0ff1..a888a67 100644 --- a/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java +++ b/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java @@ -11,7 +11,8 @@ import java.util.Scanner; */ public class MP1_CalebFontenot { - public static int[][] inputArray() { + public static int[][] inputArray() + { int m, n, i, j; // Create scanner Scanner input = new Scanner(System.in); @@ -42,11 +43,22 @@ public class MP1_CalebFontenot { return null; } - + public static boolean isConsecutiveFour(int[] values) + { + for (int i = 0; i < values.length - 4; ++i) { + if (values[i] == values[i + 1] + && values[i + 1] == values[i + 2] + && values[i + 2] == values[i + 3]) { + return true; + } else { + return false; + } + } + return false; + } - - - public static void main(String[] args) { //2965 + public static void main(String[] args) + { //2965 int[][] horizontalTestArray = { // Horizontal {0, 1, 0, 3, 1, 6, 1}, {0, 1, 6, 8, 6, 0, 1}, @@ -131,7 +143,8 @@ public class MP1_CalebFontenot { //System.out.println(isConsecutiveFour(intArray1)); } - public static void printArray(int[][] array) { + public static void printArray(int[][] array) + { int rowCounter = 0; for (int x = 0; x < array.length; x++) { for (int y = 0; y < array[x].length; y++) { @@ -144,7 +157,15 @@ public class MP1_CalebFontenot { } } - public static boolean isConsecutiveFour(int[][] values) { + public static void printArray(int[] array) + { + for (int i : array) { + System.out.print(i + " "); + } + } + + public static boolean isConsecutiveFour(int[][] values) + { int intCounter = 0, y = 0; // Horizontal checking // If the same value has been observed 4 times, return true @@ -190,14 +211,24 @@ public class MP1_CalebFontenot { System.out.println("Checking next line..."); } System.out.println("Checking for Diagonal matches..."); - for (int rowIterate = 0; rowIterate < (values.length - 4); ++rowIterate) { - for (int x = 0; x < values.length - 1; ++x) { - if (values[x][rowIterate] == values[x][rowIterate + 1]) { - } + int rows = 0; + for (int numColumns = 0; numColumns < values[0].length; numColumns++) { + int i = 0; + int j = numColumns; + int[] _1DArray = new int[numColumns + 1]; + for (int numRows = 0; numRows <= rows; ++numRows) { + System.out.println("i: " + i + " j: " + j); + _1DArray[numRows] = values[i][j]; + //printArray(_1DArray); + //System.out.println(values[rows][i] + " " + values[rows][j]); + ++i; + --j; } System.out.println("Checking next line..."); + rows++; } + System.out.println("No match found."); return false; } diff --git a/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MarkouCode.java b/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MarkouCode.java new file mode 100644 index 0000000..5b0ae62 --- /dev/null +++ b/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MarkouCode.java @@ -0,0 +1,234 @@ +/* + * 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.mp1_calebfontenot; + +/** + * + * @author caleb + */ +public class MarkouCode { + + /** + * Traverses the parm array diagonally from top left towards the top and + * prints the (i,j) indexes of the traversal. + * + * @param ar 2D array + */ + public static boolean topLeftTriangleDiagonalNothwest(int[][] ar) + { + System.out.println("diagonal indexes top-triangle of array "); + int rowCount = 0; + for (int columnCounter = 0; columnCounter < ar[0].length; ++columnCounter) + { + int i = 0; + int j = columnCounter; + int[] diagonalArray = new int[rowCount + 1]; + for (int diagonalCounter = 0; diagonalCounter <= rowCount; ++diagonalCounter) + { + diagonalArray[diagonalCounter] = ar[i][j]; + if (isConsecutiveFour(diagonalArray)) { + return true; + } + System.out.print(i + "," + j + " "); + ++i; + j--; + if (i == ar.length | j == ar[0].length) + { + break; + } + } + rowCount++; + + System.out.println(""); + + } + return false; + } + + /*Traverses the parm array diagonally from bottom right towrads the to + //and prints the (i,j) indexes of the traversal. + + * + * @param ar + */ + public static void bottomRightTriangleDiagonalNothwest(int[][] ar) + { + System.out.println("diagonal indexes bottom-triangle of array "); + + int rowCount = 0; + int numColumns = 0; + if (ar[0].length == ar.length)//square table + { + numColumns = ar[0].length - 1; + } + else if (ar[0].length > ar.length)//wide table + { + numColumns = ar.length - 1; + } + + else //narrow-width rectangle array + { + numColumns = ar[0].length; + } + + for (int columnCounter = 0; columnCounter < numColumns; ++columnCounter) + { + int i = ar.length - 1; + int j = ar[0].length - 1 - columnCounter; + for (int diagonalCounter = 0; diagonalCounter <= rowCount; ++diagonalCounter) + { + + System.out.print(i + "," + j + " "); + --i; + j++; + } + rowCount++; + System.out.println(""); + + } + //middle chunk of narrow array + + System.out.println("-----------------------"); + if (ar.length > ar[0].length) + { + System.out.println("diagonal indexes middle part of array when the array " + + "is narrow "); + + for (int i = 1; i < ar.length - ar[0].length; ++i) + { + int rowIndex = i; + int columnIndex = ar[0].length - 1; + for (int j = 0; j < ar[0].length; ++j) + { + + System.out.print(rowIndex + "," + columnIndex + " "); + rowIndex++; + columnIndex--; + + } + + System.out.println(""); + } + } + + } + + public static boolean isConsecutiveFour(int[][] values) + { + return true; + } + public static boolean isConsecutiveFour(int[] values) + { + for (int i = 0; i < values.length - 4; ++i) { + if ( values[i] == values[i+1] && + values[i+1] == values[i+2] && + values[i+2] == values[i+3] + ) { + return true; + } + else { + return false; + } + } + return false; + } + + private static void printIndexesDiagonally(int ar[][]) + { + topLeftTriangleDiagonalNothwest(ar); + System.out.println("------------------------"); + bottomRightTriangleDiagonalNothwest(ar); + } + + public static void main(String[] args) + { + int[][] ar1 = + { + { + 1, 1, 1, 1, 8 + }, + { + 1, 1, 1, 8, 9 + }, + { + 1, 1, 8, 1, 9 + }, + { + 1, 8, 1, 3, 2 + }, + }; + + int[][] ar2 = + { + { + 1, 1, 1, 1, 1, 1, 1, 1 + }, + { + 1, 1, 1, 1, 1, 1, 1, 1 + }, + { + 1, 1, 1, 1, 1, 1, 1, 1 + }, + { + 1, 1, 1, 1, 1, 1, 1, 1 + }, + { + 1, 1, 1, 1, 1, 1, 1, 1 + }, + + }; + + int[][] ar3 = + { + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + { + 1, 1, 1 + }, + + }; + System.out.println(topLeftTriangleDiagonalNothwest(ar1)); + /* + System.out.println("SQUARE array of size 4x4"); + printIndexesDiagonally(ar1); + + System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("\nWIDE array of size 8x5"); + printIndexesDiagonally(ar2); + + System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("\nNARROW array of size 10x3"); + printIndexesDiagonally(ar3); +*/ + + } +} diff --git a/Semester 2/Assignments/lab3_CalebFontenot/MyInteger.html b/Semester 2/Assignments/lab3_CalebFontenot/MyInteger.html new file mode 100644 index 0000000..2e7884f --- /dev/null +++ b/Semester 2/Assignments/lab3_CalebFontenot/MyInteger.html @@ -0,0 +1,116 @@ + + + +MyInteger.java + + + + +
/home/caleb/ASDV-Java/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/MyInteger.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.lab3_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class MyInteger {
+    
+    private int value;
+
+    /**
+     * Get the value of value
+     *
+     * @return the value of value
+     */
+    public int getValue()
+    {
+        return this.value;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 7;
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final MyInteger other = (MyInteger) obj;
+        return this.value == other.value;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "MyInteger{" + "value=" + value + '}';
+    }
+
+    public MyInteger(int value)
+    {
+        this.value = value;
+    }
+public static boolean isEven(MyInteger other) {
+    return other.getValue() % 2 == 0;
+}
+public static boolean isPrime(MyInteger other) {
+    int numToTest = other.getValue();
+    for (int i = 2; i <= numToTest / 2; ++i) {
+        if (numToTest % i == 0) {
+            return false;
+        }
+    }
+    return true;
+}
+public static int parseInteger(char[] array) {
+    String s = "";
+    for (char i: array) {
+        s += i;
+    }
+    return Integer.parseInt(String.valueOf(s));
+}
+    public static void main(String[] args)
+    {
+        
+        System.out.println(parseInteger(new char[] {'7', '6'}));
+        System.out.println(MyInteger.isPrime(new MyInteger(3)));
+        System.out.println(MyInteger.isEven(new MyInteger(4)));
+        System.out.println(MyInteger.isEven(new MyInteger(3)));
+    }
+}
+
+
+ diff --git a/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/Account.java b/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/Account.java index f7d2770..bf1381f 100644 --- a/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/Account.java +++ b/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/Account.java @@ -5,6 +5,7 @@ package com.calebfontenot.lab3_calebfontenot; import java.util.Date; +import java.util.Objects; /** * @@ -100,5 +101,46 @@ public class Account { System.out.println(account1); System.out.println(account2); + System.out.println(account1.equals(account2)); + System.out.println(account1.equals(new A())); + } -} + public void withdraw(double amount) { + this.balance -= amount; + } + // public void withdraw(double amount) { + // this.balance -= amount; + // } + + @Override + public int hashCode() + { + int hash = 3; + return hash; + } + + @Override + public boolean equals(Object obj) + { + // If the parameter obj is the same as this object + if (this == obj) { // compare addresses + return true; + } + if (obj == null) { // parameter is null + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + // here we are certain + final Account other = (Account) obj; + if (this.id != other.id) { + return false; + } + if (Double.doubleToLongBits(this.balance) != Double.doubleToLongBits(other.balance)) { + return false; + } + return Objects.equals(this.dateCreated, other.dateCreated); + } + +}class A {} diff --git a/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/MyInteger.java b/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/MyInteger.java new file mode 100644 index 0000000..736c797 --- /dev/null +++ b/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/MyInteger.java @@ -0,0 +1,85 @@ +/* + * 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.lab3_calebfontenot; + +/** + * + * @author caleb + */ +public class MyInteger { + + private int value; + + /** + * Get the value of value + * + * @return the value of value + */ + public int getValue() + { + return this.value; + } + + @Override + public int hashCode() + { + int hash = 7; + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final MyInteger other = (MyInteger) obj; + return this.value == other.value; + } + + @Override + public String toString() + { + return "MyInteger{" + "value=" + value + '}'; + } + + public MyInteger(int value) + { + this.value = value; + } +public static boolean isEven(MyInteger other) { + return other.getValue() % 2 == 0; +} +public static boolean isPrime(MyInteger other) { + int numToTest = other.getValue(); + for (int i = 2; i <= numToTest / 2; ++i) { + if (numToTest % i == 0) { + return false; + } + } + return true; +} +public static int parseInteger(char[] array) { + String s = ""; + for (char i: array) { + s += i; + } + return Integer.parseInt(String.valueOf(s)); +} + public static void main(String[] args) + { + + System.out.println(parseInteger(new char[] {'7', '6'})); + System.out.println(MyInteger.isPrime(new MyInteger(3))); + System.out.println(MyInteger.isEven(new MyInteger(4))); + System.out.println(MyInteger.isEven(new MyInteger(3))); + } +} diff --git a/Semester 2/ZIPs/lab1_CalebFontenot.zip b/Semester 2/ZIPs/lab1_CalebFontenot.zip new file mode 100644 index 0000000..e100f38 Binary files /dev/null and b/Semester 2/ZIPs/lab1_CalebFontenot.zip differ