forked from hummel/PR1-Spreadsheet
Mittelwert done (Codewort MID)
parent
910e35dd0c
commit
baa6d8a092
|
@ -70,13 +70,13 @@ public class Spreadsheet {
|
||||||
return cellName.charAt(0) - 'A';
|
return cellName.charAt(0) - 'A';
|
||||||
}
|
}
|
||||||
private int getRow(String cellName) {
|
private int getRow(String cellName) {
|
||||||
if (cellName.length()==2) {
|
if (cellName.length()==3) {
|
||||||
return cellName.charAt(1) - '1';
|
|
||||||
}else {
|
|
||||||
int Row = 0;
|
int Row = 0;
|
||||||
Row +=((cellName.charAt(1)-'0')*10);
|
Row +=((cellName.charAt(1)-'0')*10);
|
||||||
Row +=(cellName.charAt(2)-'0');
|
Row +=(cellName.charAt(2)-'0');
|
||||||
return Row-1;
|
return Row-1;
|
||||||
|
}else {
|
||||||
|
return cellName.charAt(1) - '1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// -----
|
// -----
|
||||||
|
@ -143,9 +143,9 @@ public class Spreadsheet {
|
||||||
if (formula.startsWith("SUMME(")) { // e.g. SUMME(A3:A8)
|
if (formula.startsWith("SUMME(")) { // e.g. SUMME(A3:A8)
|
||||||
result += sum(formula.substring(offset, diff), formula.substring(diff+1,offsetEnd));
|
result += sum(formula.substring(offset, diff), formula.substring(diff+1,offsetEnd));
|
||||||
}else if (formula.startsWith("PRODUKT(")) { // e.g. PRODUKT(A3:B9)
|
}else if (formula.startsWith("PRODUKT(")) { // e.g. PRODUKT(A3:B9)
|
||||||
result += prod(formula.substring(offset, diff), formula.substring(diff+1, offsetEnd));; // TODO
|
result += prod(formula.substring(offset, diff), formula.substring(diff+1, offsetEnd));
|
||||||
}else if (formula.startsWith("MITTELWERT(")) { // e.g. MITTELWERT(A3:A5)
|
}else if (formula.startsWith("MID(")) { // e.g. MITTELWERT(A3:A5)
|
||||||
result = "TODO"; // TODO
|
result += mid(formula.substring(offset, diff), formula.substring(diff+1, offsetEnd));
|
||||||
}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
|
||||||
|
@ -202,6 +202,26 @@ public class Spreadsheet {
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Method for calculating the Mid Value 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 endCellName The name of the cell in the lower right corner of the rectangle.
|
||||||
|
* @return The Mid Value calculated.
|
||||||
|
*/
|
||||||
|
private long mid(String startCellName, String endCellName) {
|
||||||
|
long res = 0;
|
||||||
|
int Numbers= 0;
|
||||||
|
for(int j = getRow(startCellName); j< (getRow(endCellName)+1);j++){
|
||||||
|
for(int i = getCol(startCellName); i< (getCol(endCellName)+1);i++) {
|
||||||
|
if(!cells[j][i].getValue().isBlank()) {
|
||||||
|
res+= Long.parseLong(cells[j][i].getValue());
|
||||||
|
Numbers++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res/=Numbers;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method calculates the result of a "normal" algebraic expression. It only needs to support
|
* This method calculates the result of a "normal" algebraic expression. It only needs to support
|
||||||
|
|
Loading…
Reference in New Issue