master
Chloe Fontenot 🏳️‍⚧️ 2023-02-07 12:59:49 +07:00
parent f5c3a529cd
commit 2763b912e3
4 changed files with 179 additions and 17 deletions

1
.gitignore vendored

@ -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/

@ -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);

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.calebfontenot</groupId>
<artifactId>MyStack</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<exec.mainClass>com.calebfontenot.mystack.MyStack</exec.mainClass>
</properties>
</project>

@ -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));
}
}