diff --git a/.gitignore b/.gitignore index ca7cd30..322973d 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,4 @@ /Semester 2/Assignments/MP2_CalebFontenot/target/ /Semester 2/Assignments/lab2_CalebFontenot/target/ /ASDV-Help/Mason/target/ +/Semester 2/Assignments/MyStack/target/ diff --git a/Semester 2/Assignments/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/Circle2D.java b/Semester 2/Assignments/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/Circle2D.java index fa7064e..844794d 100644 --- a/Semester 2/Assignments/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/Circle2D.java +++ b/Semester 2/Assignments/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/Circle2D.java @@ -211,25 +211,28 @@ public class Circle2D { int idealCount = 0; int actualCount = 0; - int arrayIndex = 0; - for (int i = 0; i < oldArray.length; ++i) { - actualCount = 0; - for (int j = 0; j < oldArray.length; ++j) { - boolean doesOverlap = oldArray[i].overlaps(oldArray[j]); - if (doesOverlap) { - ++actualCount; + int arrayIndex2 = 0; + for (int arrayIndex = 0; arrayIndex < oldArray.length; ++arrayIndex) { + for (int i = 0; i < oldArray.length; ++i) { + actualCount = 0; + for (int j = 0; j < oldArray.length; ++j) { + boolean doesOverlap = oldArray[i].overlaps(oldArray[j]); + if (doesOverlap) { + ++actualCount; + } } + if (actualCount == idealCount) { + array[arrayIndex2] = oldArray[i]; + System.out.println(oldArray[i]); + arrayIndex2++; + } + idealCount++; } - if (actualCount == idealCount) { - array[arrayIndex] = oldArray[i]; - System.out.println(oldArray[i]); - arrayIndex++; - } - idealCount++; } - System.out.println(); - return array; - } + System.out.println(); + return array; + } + public static void print(Circle2D[] array) { @@ -272,7 +275,7 @@ public class Circle2D { printPerimeter(circleArray); Circle2D[] sortedArray = sortCirclesByPerimeter(circleArray); printPerimeter(sortedArray); -print(circleArray); + print(circleArray); Circle2D[] overlapArray = Circle2D.sortCirclesByNumberOfTimesOverlapping(circleArray); print(overlapArray); diff --git a/Semester 2/Assignments/MyStack/pom.xml b/Semester 2/Assignments/MyStack/pom.xml new file mode 100644 index 0000000..53ac477 --- /dev/null +++ b/Semester 2/Assignments/MyStack/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot + MyStack + 1.0-SNAPSHOT + jar + + UTF-8 + 1.8 + 1.8 + com.calebfontenot.mystack.MyStack + + \ No newline at end of file diff --git a/Semester 2/Assignments/MyStack/src/main/java/com/calebfontenot/mystack/MyStack.java b/Semester 2/Assignments/MyStack/src/main/java/com/calebfontenot/mystack/MyStack.java new file mode 100644 index 0000000..378adb9 --- /dev/null +++ b/Semester 2/Assignments/MyStack/src/main/java/com/calebfontenot/mystack/MyStack.java @@ -0,0 +1,144 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ +package com.calebfontenot.mystack; + +import java.util.Arrays; + +/** + * + * @author caleb + */ +public class MyStack { + + private int[] elements; + private int top; + + public MyStack(int sizeOfStack) + { + elements = new int[sizeOfStack]; + } + + public MyStack() + { + elements = new int[3]; + } + + public void push(int element) + { + if (top == elements.length) { + System.out.println("Stack is full!"); + } else { + elements[top++] = element; + } + + } + + public int pop() + { + if (top == 0) { + System.out.println("Stack is empty!"); + return -1; + } else { + return elements[--top]; + } + } + + public int peek() + { + if (top == 0) { + System.out.println("Stack is empty!"); + return -1; + } else { + return elements[top]; + } + } + + public boolean empty() + { + if (top == 0) { + return false; + } + this.elements = new int[elements.length]; + this.top = 0; + return true; + } + + public int getSize() + { + return this.top; + } + + @Override + public String toString() + { + String s = "MyStack{" + "elements="; + if (this.top == 0) { + s += "No elements."; + } else { + for (int i = 0; i < this.top; ++i) { + s += this.elements[i] + ", "; + } + } + + s += "} top=" + top + '}'; + return s; + } + + @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 MyStack other = (MyStack) obj; + if (this.top != other.top) { + return false; + } + int i=0, j=0; + for (i = 0, j = 0; i < this.top && j < other.top; ++i, ++j) { + if (this.elements[i] != other.elements[j]) { + return false; + } + } + return true; +//Arrays.equals(this.elements, other.elements); + } + + public static void main(String[] args) + { + MyStack stack1 = new MyStack(5); + System.out.println(stack1); + stack1.push(10); + stack1.push(20); + System.out.println(stack1); + System.out.println("pop: " + stack1.pop()); + System.out.println( "peek: " + stack1.peek()); + System.out.println("size: " + stack1.getSize()); + System.out.println(stack1); + stack1.empty(); + stack1.push(10); + System.out.println("After empty: " + stack1); + System.out.println(); + System.out.println(stack1.equals(stack1)); + MyStack stack2 = new MyStack(2); + System.out.println(stack2.equals(stack1)); + MyStack stack3 = new MyStack(5); + stack3.push(10); + System.out.println(stack3.equals(stack1)); + } + +}