forked from hummel/PR1-Spreadsheet
Mittelwertsrechnung implementiert
parent
bc13be8b44
commit
e73b24e520
|
@ -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
|
||||
|
|
|
@ -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<werte.length;i++) {
|
||||
summe+=werte[i];
|
||||
}
|
||||
return summe/werte.length;
|
||||
|
||||
}
|
||||
|
||||
// TODO: Javadoc comments
|
||||
private int[] getValues(String startCellName, String endCellName) {
|
||||
|
|
Loading…
Reference in New Issue