From e5be43902027bfe3a76e9c6c4a94ad6960caa3aa Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 21 Oct 2014 17:26:59 +0200 Subject: [PATCH] Fixed copy error by Daniel --- StatisticsCalculator.java | 102 +++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/StatisticsCalculator.java b/StatisticsCalculator.java index b413ddd..5af1bde 100644 --- a/StatisticsCalculator.java +++ b/StatisticsCalculator.java @@ -41,59 +41,60 @@ public class StatisticsCalculator { } public static double median(ArrayList array2){ - ArrayList array = new ArrayList(); - - for(double db : array2) - { - array.add(db); - } + ArrayList array = new ArrayList(); + + for(double db : array2) + { + array.add(db); + } - Collections.sort(array); //sort the array - - double median = 0; - int middle = array.size()/2; //calculate the middle of the array + Collections.sort(array); //sort the array + + double median = 0; + int middle = array.size()/2; //calculate the middle of the array - if (array.size()%2 == 1) { //check if the array is even or uneven - median = array.get(middle); - } else { - median = (array.get(middle-1) + array.get(middle+1)) / 2; - } - return median; + if (array.size()%2 == 1) { //check if the array is even or uneven + median = array.get(middle); + } else { + median = (array.get(middle-1) + array.get(middle+1)) / 2; + } + return median; } public static double modus(ArrayList array){ - double maxValue = 0; - int maxCount = 0; - - for (int i = 0; i < array.size(); ++i){ //cycle through every number in the array - int count = 0; - for (int j = 0; j < array.size(); ++j) { - if (array.get(j) == array.get(i)){ - ++count; - } - } - if (count > maxCount) { //if the count is bigger then the max count, it will be the temporary modus - maxCount = count; - maxValue = array.get(i); - } - } - return maxValue; - } - + double maxValue = 0; + int maxCount = 0; + + for (int i = 0; i < array.size(); ++i){ //cycle through every number in the array + int count = 0; + for (int j = 0; j < array.size(); ++j) { + if (array.get(j) == array.get(i)){ + ++count; + } + } + if (count > maxCount) { //if the count is bigger then the max count, it will be the temporary modus + maxCount = count; + maxValue = array.get(i); + } + } + return maxValue; + } + public static double afwijking(ArrayList array){ - double mediaan = StatisticsCalculator.median(array); - double afwijking = 0; - for(double m :array){ - afwijking += (mediaan-m)*(mediaan-m); - } - afwijking /= array.size(); - afwijking = Math.sqrt(afwijking); - return afwijking; + double mediaan = StatisticsCalculator.median(array); + double afwijking = 0; + for(double m :array){ + afwijking += (mediaan-m)*(mediaan-m); + } + afwijking /= array.size(); + afwijking = Math.sqrt(afwijking); + return afwijking; } - public static double graagDagen(ArrayList array) - ArrayList avgTempDag = new ArrayList(); + public static double graadDagen(ArrayList array) + { + ArrayList avgTempDag = new ArrayList(); int i = 0; double avgTemp = 0; @@ -129,6 +130,7 @@ public class StatisticsCalculator { //graaddagen afronden return graaddagen; + } public static int[] langsteDroogstePeriode(ArrayList array) { @@ -213,12 +215,12 @@ public class StatisticsCalculator { //Doorloop je maximale temperaturen en zoek de langste periode for(int t=0; t 25) { - p++; - if(!zomers) - { - zomers = true; - index1_1 = t; - } + p++; + if(!zomers) + { + zomers = true; + index1_1 = t; + } } else { if(p > maxDays) {