forked from hummel/PR1-Spreadsheet
MITTELWERT( added
parent
d8a057e995
commit
dc301c13fa
|
@ -189,7 +189,7 @@ public class Spreadsheet {
|
|||
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
|
||||
result = "" + pro(formula.substring(8, 10), formula.substring(11, 13));
|
||||
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
|
||||
result = "TODO"; // TODO
|
||||
result = "" + mittelwert(formula.substring(11, 13), formula.substring(14, 16));
|
||||
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
|
||||
result = "TODO"; // TODO
|
||||
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> kleinster Wert
|
||||
|
@ -214,7 +214,6 @@ public class Spreadsheet {
|
|||
* @return The sum calculated.
|
||||
*/
|
||||
private long sum(String startCellName, String endCellName) {
|
||||
// TODO implement
|
||||
int startCellRow = getRow(startCellName);
|
||||
int startCellCol = getCol(startCellName);
|
||||
int endCellRow = getRow(endCellName);
|
||||
|
@ -294,6 +293,27 @@ public class Spreadsheet {
|
|||
return res;
|
||||
}
|
||||
|
||||
private long mittelwert(String startCellName, String endCellName) {
|
||||
int startCellRow = getRow(startCellName);
|
||||
int startCellCol = getCol(startCellName);
|
||||
int endCellRow = getRow(endCellName);
|
||||
int endCellCol = getCol(endCellName);
|
||||
|
||||
long anzahl = 0;
|
||||
|
||||
long res = 0;
|
||||
|
||||
for (int i = startCellRow; i <= endCellRow; i++) {
|
||||
for (int j = startCellCol; j <= endCellCol; j++) {
|
||||
res = res + (Integer.parseInt(cells[i][j].getValue()));
|
||||
anzahl++;
|
||||
}
|
||||
}
|
||||
res = res/anzahl;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calculates the result of a "normal" algebraic expression. It only needs to support
|
||||
* expressions like =B4 or =2+A3-B2, i.e. only with int numbers and other cells and with plus,
|
||||
|
|
Loading…
Reference in New Issue