new semester, new repo structure

This commit is contained in:
2023-01-10 11:59:05 -06:00
parent 0a76658f85
commit ba6de6e18e
725 changed files with 1199 additions and 103 deletions

View File

@@ -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.mycompany</groupId>
<artifactId>mavenproject1</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.mycompany.mavenproject1.Mavenproject1</exec.mainClass>
</properties>
</project>

View File

@@ -0,0 +1,20 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class BitwiseOR {
public static void main(String[] args) {
int x = 1;
int y = 5;
while (y-- > 0 ^ x++ < 100);
System.out.println(++x);
}
}

View File

@@ -0,0 +1,18 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class ByteOverFlow {
public static void main(String[] args)
{
byte b = 127;
b++;
System.out.println(b);
}
}

View File

@@ -0,0 +1,23 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class CompareTo {
public static void main(String[] args)
{
System.out.println("Abcd".compareTo("abc"));
System.out.println("abc".compareTo("Abcd"));
String s1 = "abcd", s2 = "ab";
System.out.println(!s2.contains(s1));
System.out.println(!(!s1.contains(s2) || !s1.contains(s2) ));
System.out.println(!s1.contains(s2));
}
}

View File

@@ -0,0 +1,26 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Exercise_05_18_C {
public static void main(String[] args) {
// Display pattern C
int numberOfLines = 6;
System.out.println("Pattern C");
for (int rows = 1; rows <= numberOfLines; rows++) {
for (int s = numberOfLines - rows; s >= 1; s--) {
System.out.print(" ");
}
for (int col = rows; col >= 1; col--) {
System.out.print(col + " ");
}
System.out.println();
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Exercise_05_19 {
public static void main(String[] args) {
int startRight = 0, // Initialize decending numbers
endSpace = 7; // Initialize number of white space in row
// Display number of rows and numbers in each row
for (int row = 1; row <= 128; row += row) {
// Display white space
for (int startSpace = 0; startSpace < endSpace; startSpace++) {
System.out.print(" ");
}
// Display acending numbers
for (int l = 1; l <= row; l += l) {
System.out.printf("%4d", (l));
}
// Display decending numbers
for (int r = startRight; r > 0 ; r /= 2 ) {
System.out.printf("%4d", (r));
}
System.out.println(); // End line
endSpace--; // Decrement endSpace
startRight = row; // Assign row to startRight
}
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.mycompany.mavenproject1;
import java.util.concurrent.TimeUnit;
/**
*
* @author caleb
*/
public class LogicalExpression {
public static void main(String[] args) {
int x = -10;
boolean hasCycled = false;
while (true) {
//System.out.print(((x > 1) || ( x < 100) ) && (x < 0)); //incorrect
System.out.print("Logical Expression result: ");
System.out.print(x < 100 && x > 1 || (x < 0)); //correct
System.out.print(": " + x);
if (x >= 150 & hasCycled == false) {
hasCycled = true;
} else if (x <= -10) {
hasCycled = false;
}
if (hasCycled) {
System.out.println(" state: currently subtracting 1");
x--;
} else {
System.out.println(" state: currently adding 1");
x++;
}
try {
TimeUnit.MILLISECONDS.sleep(250); //waits for a specified amount of time
} catch (Exception e) {
System.out.print("lol");
}
}
}
}

View File

@@ -0,0 +1,22 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Loop12 {
public static void main(String[] args) {
int lol = 0;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < i; j += 2) {
System.out.println("java" + ++lol);
}
}
}
}

View File

@@ -0,0 +1,21 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Loop13 {
public static void main(String[] args)
{
int count = 12;
do {
System.out.println("Welcome to Java");
} while (count-- > 8);
}
}

View File

@@ -0,0 +1,26 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Loop15 {
public static void main(String[] args)
{
int balance = 8;
while (true) {
if (balance++ < 15) {
break;
}
balance += 2;
}
System.out.println(balance--);
}
}

View File

@@ -0,0 +1,23 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class LoopDivision {
public static void main(String[] args)
{
double sum = 0;
double d = 0;
while (d != 10.0) {
d += 0.1;
sum += sum + d;
System.out.println(sum);
}
}
}

View File

@@ -0,0 +1,19 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class LulyBoolean {
public static void main(String[] args)
{
boolean even = false;
System.out.println((even ? true : false));
System.out.println(even);
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.mycompany.mavenproject1;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class MathRounding {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double toRound = 1;
while (toRound != 0)
{
System.out.println("Time to find out what this shit does: (hit 0 to fuck off) ");
toRound = scan.nextDouble();
if (toRound == 0)
break;
System.out.println("Math.rint gives you " + Math.rint(toRound));
System.out.println("Math.ceil gives you " + Math.ceil(toRound));
System.out.println("Math.round gives you " + Math.round(toRound));
System.out.println("Math.floor gives you " + Math.floor(toRound));
}
System.out.println("Goodbye!");
}
}

View File

@@ -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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Mavenproject1 {
public static void main(String[] args)
{
int x = 10;
int y = 1;
System.out.println(x ^ y); // result is 11
System.out.println(x & y); //result is 0
System.out.println(x | y); // result is 11
System.out.println(0 ^ 1); // result is 1
System.out.println(1 ^ 1); // result is 0
System.out.println(0 ^ 0); // result is 11 (Wrong Markou, Wrong)
}
}

View File

@@ -0,0 +1,16 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class NegativeChar {
public static void main(String[] args) {
char lolChar = '\5';
System.out.println(lolChar);
}
}

View File

@@ -0,0 +1,17 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class NegativeVariableTest {
public static void main(String[] args)
{
int x = 5;
System.out.println(-x);
}
}

View File

@@ -0,0 +1,16 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class NotDemo {
public static void main(String[] args)
{
System.out.println(!true);
}
}

View File

@@ -0,0 +1,19 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class PrePostIncrement {
public static void main(String[] args)
{
int j = 2;
int i = j++ + j * j + 1;
System.out.println("i is: " + i);
}
}

View File

@@ -0,0 +1,28 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Q20 {
public static void main(String[] args) {
int x = 0;
int y = 10;
while ( -x > -5)
{
while ( y % 5 == 0 )
{
y -= 5;
if ( y < 0 )
break;
}
x++;
}
System.out.println(x+y);
}
}

View File

@@ -0,0 +1,16 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Rint {
public static void main(String[] args) {
System.out.println( Math.rint(5.5) );
System.out.println( Math.rint(4.5) );
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Test
{
public static void main(String[] args)
{
int list[] =
{
5, 4, 3, 2, 1
};
for (int i = 1; i < list.length; i++)
{
list[i] = list[i - 1];
}
for (int i = 0; i < list.length; i++)
{
System.out.print(list[i] + " ");
}
}
}

View File

@@ -0,0 +1,168 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
import java.util.Scanner;
public class Tyler {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double percentage = 0.3; //initializing variables
System.out.print("Enter the number of players: ");
int size = in.nextInt();
System.out.println("Contest with percentage set to 0.3: "); //each contest with percentages assigned
System.out.println();
contest(size, percentage);
percentage = 0.2;
System.out.println("Contest with percentage set to 0.2: ");
System.out.println();
contest(size, percentage);
percentage = 0.1;
System.out.println("Contest with percentage set to 0.1: ");
System.out.println();
contest(size, percentage);
}
public static int getWinner(int one, int two) { //randomly decides winner, if loop says all
double random = Math.random();
if (random <= 0.5) {
return one;
}
else {
return two;
}
}
public static boolean contestRound(int[] array) { //changes the values in the array
int first = (int) Math.round(Math.random() * array.length); //randomly assigns variables for the two indecies of
if (first == 10) { //the values that we will change. None of the variables
first--; //will equal the length of the array
}
while (array[first] == 0) { //Finds an index of the array where the value is positive when the value is zero
first = (int) Math.round(Math.random() * array.length);
if (first == 10) {
first--;
}
}
int second = (int) Math.round(Math.random() * array.length );
if (second == 10) {
second--;
}
while (array[second] == 0 && second != first) {
second = (int) Math.round(Math.random() * array.length);
if (second == 10) {
second--;
}
}
int returned = getWinner(first, second); //sees who wins
if (returned == array[first]) { //changes index values based on who won
array[first]++;
array[second]--;
}
else {
array[second]++;
array[first]--;
}
if (array[first] == 0 || array[second] == 0) { //return statement
return true;
}
else {
return false;
}
}
public static int countPlayers(int[] array) { // counts all the non-zero numbers in the token array
int count = 0;
for (int element : array)
if (element != 0)
count++;
return count;
}
public static void printPlayers(int[] array) { // prints out the non-zero parts of the token array
int highest=0, highestAt=0, lowest=100, lowestAt=0; //initializes variables
System.out.print("Players "); //prints out the index of each player with a positive value
for (int i = 0; i < array.length; i++)
if (array[i] != 0)
System.out.print(i + " ");
System.out.println();
System.out.print("Values "); //prints the values of the indexes from before
for (int i = 0; i < array.length; i++) {
if (array[i] != 0) {
System.out.print(array[i] + " ");
}
}
int count = 0;
for (int i = 0; i < array.length; i++) { //Could not find a better way to figure out which is highest and which
if (array[i] > 0) { //is lowest, so created new array with only the positive values.
count++; //this loop calculates how many positive values there are to set the
} //length of the new index
}
int[] positives = new int[count];
int pos = 0;
for (int i = 0; i < array.length; i++) { //finds the values of the initialized variables
if (array[i] > 0) {
positives[pos] = array[i];
pos++;
}
if (array[i] > highest) {
highest = array[i];
highestAt = i;
}
if (array[i] < lowest && array[i] != 0){
lowest = array[i];
lowestAt = i;
}
}
System.out.println(); //prints out the variables
System.out.println("Highest Player Index: " + highestAt + ", Value : " + highest + "; Lowest Player Index: " + lowestAt + ", Value: " + lowest);
System.out.println();
}
public static void contest(int size, double percentage) { // calls other methods to do the contest
int square = (int) Math.ceil(Math.sqrt(size));
int[] array = new int[size]; //creates the array we'll use for the contest
for (int i = 0; i < array.length; i++) { //assigns each value of the array the same thing
array[i] = square;
}
printPlayers(array); //prints the first line
int perc = (int) Math.round(array.length * percentage); //calculates which is higher, 2 or the percentage of the length
if (perc < 2) {
perc = 2;
}
int count = countPlayers(array);
boolean contesting = contestRound(array); //loop that does the contests
while (count > perc) {
contesting = contestRound(array);
if (contesting == true) {
printPlayers(array);
count = countPlayers(array);
}
}
}
}

View File

@@ -0,0 +1,22 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class TypeCasting {
public static void main(String[] args)
{
double b = 5.3;
int c = (int) b;
double d = ((double) 1 / 2);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
}

View File

@@ -0,0 +1,18 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class Unicode {
public static void main(String[] args)
{
//System.out.println("\u2764");
char char_a = 'a', char_0 = '2', char_A = 'A';
System.out.println((int) char_0 + " = 0\n" + (int) char_a + " = a\n" + (int) char_A + " = A");
}
}

View File

@@ -0,0 +1,16 @@
/*
* 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.mycompany.mavenproject1;
/**
*
* @author caleb
*/
public class WeirdCharStuff {
public static void main(String[] args) {
char c = '2' + 2;
System.out.println((int) c + 4);
}
}