diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 8e43a72..f01ed5a 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -174,9 +174,16 @@ public class Spreadsheet { - else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung - result = "TODO"; // TODO - else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert + else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> Standardabweichung + String[] onlyCells = formula.substring(6, formula.length() - 1).split(":"); + + if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) { + result = "" + statbw(onlyCells[0], onlyCells[1]); + } + + } + + else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert result = "TODO"; // TODO else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung result = "TODO"; // TODO @@ -193,6 +200,8 @@ public class Spreadsheet { + + /** * Method for calculating the sum of a rectangular block of cells, such as from A1 to B3. * @param startCellName The name of the cell in the upper left corner of the rectangle. @@ -209,7 +218,7 @@ public class Spreadsheet { return summe; } - +// TODO: Javadoc comments private long pro(String startCellName, String endCellName) { int werte[]=getValues(startCellName,endCellName); @@ -220,6 +229,7 @@ public class Spreadsheet { return produkt; } +// TODO: Javadoc comments private long mit(String startCellName, String endCellName) { int werte[]=getValues(startCellName,endCellName); @@ -231,6 +241,33 @@ public class Spreadsheet { } +// TODO: Javadoc comments + private double statbw(String startCellName, String endCellName) { + int werte[]=getValues(startCellName,endCellName); + + if (werte.length < 2) { + return 0; // Die Standardabweichung für weniger als zwei Werte ist 0 + } + + double summe = 0.0; + for (double i : werte) { + summe += i; + } + + // Durchschnitt des Arrays berechnen + double mittel = summe / werte.length; + + // abweichung zum mittelwert berchnen und quadrieren + double standardDeviation = 0.0; + for (double wert : werte) { + standardDeviation += Math.pow(wert - mittel, 2); + } + + return Math.sqrt(standardDeviation / werte.length); + } + + + // TODO: Javadoc comments private int[] getValues(String startCellName, String endCellName) { int startZeile=getRow(startCellName);