diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index f01ed5a..5a1d555 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -183,8 +183,17 @@ public class Spreadsheet { } - else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert - result = "TODO"; // TODO + else if (formula.startsWith("MIN(")) { + String[] onlyCells = formula.substring(4, formula.length() - 1).split(":"); + if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) { + result = "" + min(onlyCells[0], onlyCells[1]); + } + + + } + + + else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung result = "TODO"; // TODO else if (!formula.isEmpty()) { @@ -202,6 +211,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. @@ -258,16 +269,36 @@ public class Spreadsheet { double mittel = summe / werte.length; // abweichung zum mittelwert berchnen und quadrieren - double standardDeviation = 0.0; + double abweichung = 0.0; for (double wert : werte) { - standardDeviation += Math.pow(wert - mittel, 2); + abweichung += Math.pow(wert - mittel, 2); } - return Math.sqrt(standardDeviation / werte.length); + return Math.sqrt(abweichung / werte.length); } + + private long min(String startCellName, String endCellName) { + int werte[]=getValues(startCellName,endCellName); + + if (werte.length == 0) { + return 0; // Handle an empty array as needed + } + + int minValue = werte[0]; + + for (int i = 1; i < werte.length; i++) { + if (werte[i] < minValue) { + minValue = werte[i]; + } + } + + return minValue; + + } + // TODO: Javadoc comments private int[] getValues(String startCellName, String endCellName) { int startZeile=getRow(startCellName);