First commit

This commit is contained in:
Frank
2025-08-12 19:39:02 -06:00
commit eeb269ea63
11 changed files with 320 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

5
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Environment-dependent path to Maven home directory
/mavenHomeManager.xml

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" default="true" project-jdk-name="openjdk-24" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/java-practice.iml" filepath="$PROJECT_DIR$/java-practice.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

11
java-practice.iml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

1
readme.md Normal file
View File

@@ -0,0 +1 @@
## This is a Repository to keep my CS 109 Projects in

130
src/ArraySorting.java Normal file
View File

@@ -0,0 +1,130 @@
import java.util.Arrays;
import java.util.Random;
public class ArraySorting {
public static void main(String[] args) {
Random rand = new Random();
int[] numbers = new int[100000000];
for(int i = 0; i < numbers.length; i++) {
numbers[i] = rand.nextInt(10000);
}
System.out.println("Before: ");
// mergeSort(numbers, 0, numbers.length - 1);
// selectionSort(numbers);
// bubbleSort(numbers);
// Arrays.sort(numbers);
// insertionSort(numbers, 4, 8);
System.out.println("After: ");
}
public static void quickSort(int[] numbers) {
}
/* MERGE SORT ALGORITHM */
public static void mergeSort(int[] array, int left, int right) {
if(left < right) {
int mid = (left+right) / 2; // Find the middle element
mergeSort(array, left, mid); // Sort the first half
mergeSort(array, mid + 1, right); // Sort the second half
merge(array, left, mid, right); // Merge the sorted halves
}
}
public static void merge(int[] array, int left, int mid, int right) {
// Find sizes of two subarrays to be merged
int n1 = mid - left + 1;
int n2 = right - mid;
// Create Temp Arrays
int[] leftTemp = new int[n1];
int[] rightTemp = new int[n2];
// Copy Data to Temp Arrays
for(int i = 0; i < n1; i++) {
leftTemp[i] = array[left + i];
}
for(int j = 0; j < n2; j++) {
rightTemp[j] = array[mid + 1 + j];
}
// Merge the temp arrays
// Initial index of merged subarray array
int i = 0, j = 0, k = left;
while (i < n1 && j < n2) {
if (leftTemp[i] <= rightTemp[j]) {
array[k] = leftTemp[i];
i++;
} else {
array[k] = rightTemp[j];
j++;
}
k++;
}
// Copy remaining elements of leftTemp if any
while (i < n1) {
array[k] = leftTemp[i];
i++;
k++;
}
// Copy remaining elements of rightTemp if any
while (j < n2) {
array[k] = rightTemp[j];
j++;
k++;
}
}
/* END: MERGE SORT ALGORITHM */
private static void selectionSort(int[] numbers) {
for(int i = 0; i < numbers.length - 1; i++) {
int smallest = i;
// Find the smallest element in unsorted array
for(int j = i + 1; j < numbers.length; j++) {
if(numbers[j] < numbers[smallest]) {
smallest = j;
}
}
// Swap the smallest element with the first element
int temp = numbers[smallest];
numbers[smallest] = numbers[i];
numbers[i] = temp;
}
}
private static void bubbleSort(int[] numbers) {
int temp;
for( int i = 0; i < numbers.length; i++) {
for(int j = 0; j < numbers.length - 1; j++) {
if (numbers[j] > numbers[j + 1]) {
temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
}
private static void insertionSort(int[] numbers, int start, int end) {
int temp;
for (int i = start; i < end; i++) {
for (int j = i; j > start; j--) {
if (numbers[j] < numbers[j - 1]) {
temp = numbers[j];
numbers[j] = numbers[j - 1];
numbers[j - 1] = temp;
}
}
}
}
}

27
src/Employee.java Normal file
View File

@@ -0,0 +1,27 @@
public class Employee {
private double payRate;
private String fullName;
private double FTE;
float hoursWorked;
public static void main(String[] args) {
}
public double calculatePay() {
return getPayRate() * getFTE() * getHoursWorked();
}
public double getPayRate() {
return payRate;
}
public double getFTE() {
return FTE;
}
public float getHoursWorked() {
return hoursWorked;
}
}

80
src/Main.java Normal file
View File

@@ -0,0 +1,80 @@
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
// System.out.println(addTotals(2.5, 2.5));
// System.out.println(addTotals(5, 5));
// Modulus Example
// int a = 864;
// int b = 183;
// System.out.println("GCD of a and b is " + calcGcd(a, b));
// Iterative factorial
//System.out.println(factorialIterative(3));
// reverse string
//String name = "Frank";
//System.out.println(reverseStringRecursive(name));
// Towers of Hanoi
//int disks = 4;
//solvePuzzle(disks, "Peg 1", "Peg 2", "Peg 3");
}
private static int addTotals(int x, int y) {
return x + y;
}
private static double addTotals(double x, double y) {
return x + y;
}
private static String reverseStringRecursive(String str) {
if (str.isEmpty()) {
return "";
} else {
return (reverseStringRecursive(str.substring(1)) + str.charAt(0));
}
}
static void solvePuzzle(int n, String begin, String temp, String end) {
if (n == 1) {
System.out.println(begin + " ---> " + end);
} else {
solvePuzzle(n - 1, begin, end, temp);
System.out.println(begin + " ---> " + end);
solvePuzzle(n - 1, temp, begin, end);
}
}
public static long calcGcd(int a, int b) {
if(b != 0) {
System.out.println(a + " " + b + " = " + a % b);
return calcGcd(b, a % b);
} else {
return a;
}
}
static int printFibonacci(int n) {
if (n == 0) {
return 0;
}
if (n == 1 || n == 2) {
return 1;
}
return printFibonacci(n - 2) + printFibonacci(n - 1);
}
private static long factorialIterative (int num) {
int theFactorial = 1;
for (int i = 1; i <= num; i++) {
theFactorial *= i;
}
return theFactorial;
}
}

17
src/UnionEmployee.java Normal file
View File

@@ -0,0 +1,17 @@
public class UnionEmployee extends Employee {
private String bargainingUnit;
private String unionCode;
private double unionDues;
public static void main(String[] args) {
}
public double getUnionDues() {
return unionDues;
}
public double calculatePay() {
return (super.calculatePay() - getUnionDues());
}
}