diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index d8c0366..a4f9609 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -198,7 +198,7 @@ public class Axel { if (userInput.toUpperCase().matches("[A-Za-z][1-9][0-9]?=" + "((((([A-Za-z][1-9][0-9]?)|([0-9]+))(\\*|\\+|\\-|\\/))*" + "(([A-Za-z][1-9][0-9]?)|([0-9]+)))|" - + "((SUMME|PRODUKT|MID|STABW|MIN|MAX)\\(([A-Za-z][1-9][0-9]*\\:[A-Za-z][1-9][0-9]*)\\)))")){ + + "((SUMME|PRODUKT|MITTEL|STABW|MIN|MAX)\\(([A-Za-z][1-9][0-9]*\\:[A-Za-z][1-9][0-9]*)\\)))")){ String[] parts = userInput.split("="); //prüft ob eingegebene Zelle im spreadsheet existiert diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 91c295e..8e43a72 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -164,8 +164,16 @@ public class Spreadsheet { - else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) - result = "TODO"; // TODO + else if (formula.startsWith("MITTEL(")) { // e.g. MITTEL(A3:A5) + String[] onlyCells = formula.substring(7, formula.length() - 1).split(":"); + + if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) { + result = "" + mit(onlyCells[0], onlyCells[1]); + } + } + + + 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 @@ -183,6 +191,8 @@ public class Spreadsheet { cells[row][col].setValue("" + result); } + + /** * 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. @@ -210,7 +220,16 @@ public class Spreadsheet { return produkt; } - + private long mit(String startCellName, String endCellName) { + int werte[]=getValues(startCellName,endCellName); + + int summe=0; + for(int i=0;i