From a07ef7df60fd49f0d9a0298eb9299385bd6ae966 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Tue, 18 Oct 2022 09:54:27 -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 zcma)9U2GKB75?t-%XrnWgrsQ;v;jh>EJajmqsq9Y;;B;AzVsoj`kI#_RjHJxN>%E_{qD>@$@-JKH{xF&)QpD-g$mC^QWVvFHIU17k(c$_a#QM?mlOCGC8B+9{O0 z0nfF}Tt^&HR7v}b1s-dDBumR+r2GAi{v%E48kV4r9_34Pa8Bz!*LG&L#!xTNw9D}< z*YHLy!ztyCk<1@A3R!c^a*JDyI1*@#qDjM-uvDOC*136V1k{35N-Jg0{M^uU+ZpL- z8I-;+)36*X1fq_0)=NuXW-1-SDuI4=< z(;Fp@T+gDi(0p8$^DT=ol$PLc#VHLgie$*JcHV;wX~|I1 za2jWP2EP^d2Q~IJFe}Q={IDfZ*=sx2UcW^Tn8&i*sqW2Z%+x zAKquWX3pZ&q3Uqn;bGW2!wfDQ@XXA~KC@5`MKxX59OGadqO5w{c8e@Tq-e2sS+1CC zc_r7eNJg!!mE+hTm!IP(F4CaQgV6vREN+?FE>&cG3{XWt$i0d}zG!>)X-oP{S$cPwNd1P>^Q90`pAIO(Dt#;e87IA;Dw8{3uGS)QYw{8@42@$@}^1Gd@;HoC? zK>UhC2xEN9WAIiu$F~+R;2ZcRzbf!8e4AWS_&&l^1suDJ=%M#eafg7YMRoc;)K)(> ziH5b4Fj9*AS~-c;Tqn_@E6r0_TZ;`o*T#qTH~afrKDR&T*$!0EVkH(}G2hjwLk*gs zV-@d~wfx$EdTd4mr&)sIsS#=35`9>Tr(s}-X)rnUWmHKh(sMkI7q~9KK}P!>Mp}sh zyom2I!Y1s(IKD@|?~_9nWR>A_w3Wj@&LgR$Y6@RXH`k*3@>@_FZYOSYFYKqW+CN{# z_iCnb4HnU?G;Z*mayU=*@~Og0q*zvRb@|3$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