1
0
Fork 0

Mittelwertsrechnung implementiert

master
devra 2024-01-08 21:27:41 +01:00
parent bc13be8b44
commit e73b24e520
2 changed files with 23 additions and 4 deletions

View File

@ -198,7 +198,7 @@ public class Axel {
if (userInput.toUpperCase().matches("[A-Za-z][1-9][0-9]?=" 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]+))(\\*|\\+|\\-|\\/))*"
+ "(([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("="); String[] parts = userInput.split("=");
//prüft ob eingegebene Zelle im spreadsheet existiert //prüft ob eingegebene Zelle im spreadsheet existiert

View File

@ -164,8 +164,16 @@ public class Spreadsheet {
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) else if (formula.startsWith("MITTEL(")) { // e.g. MITTEL(A3:A5)
result = "TODO"; // TODO 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 else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
result = "TODO"; // TODO result = "TODO"; // TODO
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert 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); cells[row][col].setValue("" + result);
} }
/** /**
* Method for calculating the sum of a rectangular block of cells, such as from A1 to B3. * 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. * @param startCellName The name of the cell in the upper left corner of the rectangle.
@ -210,7 +220,16 @@ public class Spreadsheet {
return produkt; return produkt;
} }
private long mit(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
int summe=0;
for(int i=0;i<werte.length;i++) {
summe+=werte[i];
}
return summe/werte.length;
}
// TODO: Javadoc comments // TODO: Javadoc comments
private int[] getValues(String startCellName, String endCellName) { private int[] getValues(String startCellName, String endCellName) {