From 44ca15a7a185896cdb0279a01361930cde555ea2 Mon Sep 17 00:00:00 2001 From: Chloe Christine Fontenot Date: Sun, 19 Oct 2025 21:30:57 -0500 Subject: [PATCH] More NetBeans moments --- .../src/mp3_calebfontenot/Stats.java | 46 ++++- .../com/mycompany/mavenproject1/Tyler.java | 168 ++++++++++++++++++ .../com/mycompany/mavenproject1/Tyler.class | Bin 0 -> 3639 bytes 3 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 Test Project/src/main/java/com/mycompany/mavenproject1/Tyler.java create mode 100644 Test Project/target/classes/com/mycompany/mavenproject1/Tyler.class diff --git a/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java b/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java index 8aac525..bcb3fae 100644 --- a/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java +++ b/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java @@ -4,13 +4,53 @@ */ package mp3_calebfontenot; +import java.util.Scanner; + /** * * @author caleb */ public class Stats { - public static void main(String[] args) - { - + + public static void main(String[] args) { + // Create scanner + Scanner input = new Scanner(System.in); + // Define variables + double mean = 0; //It's twice as mean + double inputSum = 0, numberOfTimesRun = 0, inputPow = 0, deviation = 0; + String userInput = ""; + + // Prompt for input + do { + System.out.println("Press Y/y to enter a series of numbers or Q/q to quit."); + System.out.println("Current sum: " + inputSum); + userInput = input.next(); + if (userInput.toLowerCase().equals("y")) { + try { + do { + System.out.print("Please enter a series of numbers; Type '-1' to quit (no quotes, you doofus!): "); + userInput = input.next(); + if (Double.parseDouble(userInput) != -1) { + inputSum += Double.parseDouble(userInput); + inputPow += Math.pow(Double.parseDouble(userInput), 2); + numberOfTimesRun++; // counter to store number of times we've added to input sum + } + System.out.println("Current sum: " + inputSum); + System.out.println("Input sum^2: " + inputPow); + } while (Double.parseDouble(userInput) != -1); + } catch (Exception e) { + System.out.println("Invalid input!"); + } + } + // Calculate mean + mean = inputSum / numberOfTimesRun; + // Calculate deviation + deviation = ((numberOfTimesRun - 1) / (inputPow - (Math.pow(inputSum, 2) / numberOfTimesRun))); + + System.out.println(); + System.out.println("The mean is: " + mean); + System.out.println("The deviation is: " + deviation); + + } while (!(userInput.toLowerCase().equals("q"))); } } diff --git a/Test Project/src/main/java/com/mycompany/mavenproject1/Tyler.java b/Test Project/src/main/java/com/mycompany/mavenproject1/Tyler.java new file mode 100644 index 0000000..8ed77f2 --- /dev/null +++ b/Test Project/src/main/java/com/mycompany/mavenproject1/Tyler.java @@ -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); + } + } + } +} \ No newline at end of file diff --git a/Test Project/target/classes/com/mycompany/mavenproject1/Tyler.class b/Test Project/target/classes/com/mycompany/mavenproject1/Tyler.class new file mode 100644 index 0000000000000000000000000000000000000000..dfd73f107b8c2fa9992f714b7c0d884fc573dc7c GIT binary patch literal 3639 zcmX^0Z`VEs1_l#``CJT449x5dEIbUX3~Y=H0$GV=iTXK-dFlH8Nm;4MC5#MgHko;u zC3cJq%o>_u>#hBtxMfwJ13?uOu-&RiQYwM4=>K!9dR# z;tX{j1`UuK*ul2tFSA2>9@q2-%clEKKpR+N~RlAj9>9TztH2Ml1q#bCwY z#KYjs;KInjT9jX!m%_-vqT!Mh0<&m5>N>D$UGENiE`H@Md5J5&k?30StkR3~Y%71*ssLWHdZAAqfub zP!wI(91OvX49p4&3LveaAgy7H47%8o0Zt=8IwN=(A{n9>88}MvA?7nOh-hHiYR$nA z!^prDmY7qTTCAX;puoWp$H*Y&k(r(WNbLKQ>eDUF9Aogssffu*>xs00$=E})pm;$g@JizlaM=73@#mxm#b zA)k?f2b?Y;jwl92LbN9+@#`=Y@-P%J6f-jLB_adYSTi!P2p5ixP8FOHzx9LFH3kDkB4PNqIga18;CiVsf@`Vgb}E ztcgWMiIt2DOwpc<46JFHMa7`9wm3C8ACxdTic(8Ti}F%a7#Y}8b5e6tLB$FyIE>jD zx)~W5GZ`7!GazY$k%1G+as(NX15N{s3>**!NQ|=}zc{lbvn&V;C^G0UFoCl!I|C!A z(qLd@s9<1V&}U#|U}RumVAa~rz_^itfq{vkl7WGN4J^pZP{qK&zyoHpGE_6vFfcH1 zGSo8EF))EOKVx8KU}a!nNZQT79=VBub2|gSj|hX1=OzXbA&G4aQrg=X6wFvaJe6$> zYMU5DwlQdmvS{pJ&=z4Z1gkQ}5H|&jo1=*%T;{|ez`(%3&%n(f$iUAa#30Tf%pl7k z%Am?1#-Pn0&S1zO$zaML#bC=I&EU)+!{Esv$KcB#&k)L>z!1%#$dJgO1oo8{0}III z4D}2R3=9n14B-sC42=wo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