forked from hummel/PR1-Spreadsheet
SUMME(, PRODUKT(, MAX(, MIN( added
parent
3f4f1d978a
commit
d8a057e995
|
@ -187,15 +187,15 @@ 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(6, 8), formula.substring(9, 11)); // TODO adapt to cells with two digits
|
result = "" + sum(formula.substring(6, 8), formula.substring(9, 11)); // TODO adapt to cells with two digits
|
||||||
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
|
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
|
||||||
result = "TODO"; // TODO
|
result = "" + pro(formula.substring(8, 10), formula.substring(11, 13));
|
||||||
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
|
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
|
||||||
result = "TODO"; // TODO
|
result = "TODO"; // TODO
|
||||||
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) -> kleinster Wert
|
||||||
result = "TODO"; // TODO
|
result = "" + min(formula.substring(4, 6), formula.substring(7, 9));
|
||||||
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
|
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert
|
||||||
result = "TODO"; // TODO
|
result = "" + max(formula.substring(4, 6), formula.substring(7, 9));
|
||||||
else if (!formula.isEmpty()) {
|
else if (!formula.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
result = "" + calculate(formula); //geht nicht?
|
result = "" + calculate(formula); //geht nicht?
|
||||||
|
@ -215,8 +215,83 @@ public class Spreadsheet {
|
||||||
*/
|
*/
|
||||||
private long sum(String startCellName, String endCellName) {
|
private long sum(String startCellName, String endCellName) {
|
||||||
// TODO implement
|
// TODO implement
|
||||||
|
int startCellRow = getRow(startCellName);
|
||||||
|
int startCellCol = getCol(startCellName);
|
||||||
|
int endCellRow = getRow(endCellName);
|
||||||
|
int endCellCol = getCol(endCellName);
|
||||||
|
|
||||||
return 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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long pro(String startCellName, String endCellName) {
|
||||||
|
int startCellRow = getRow(startCellName);
|
||||||
|
int startCellCol = getCol(startCellName);
|
||||||
|
int endCellRow = getRow(endCellName);
|
||||||
|
int endCellCol = getCol(endCellName);
|
||||||
|
|
||||||
|
long res = 0;
|
||||||
|
|
||||||
|
for (int i = startCellRow; i <= endCellRow; i++) {
|
||||||
|
for (int j = startCellCol; j <= endCellCol; j++) {
|
||||||
|
if (res == 0) {
|
||||||
|
res = Integer.parseInt(cells[i][j].getValue());
|
||||||
|
} else {
|
||||||
|
res = res * (Integer.parseInt(cells[i][j].getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long min(String startCellName, String endCellName) {
|
||||||
|
int startCellRow = getRow(startCellName);
|
||||||
|
int startCellCol = getCol(startCellName);
|
||||||
|
int endCellRow = getRow(endCellName);
|
||||||
|
int endCellCol = getCol(endCellName);
|
||||||
|
|
||||||
|
long res = Long.MAX_VALUE;
|
||||||
|
long merker;
|
||||||
|
|
||||||
|
for (int i = startCellRow; i <= endCellRow; i++) {
|
||||||
|
for (int j = startCellCol; j <= endCellCol; j++) {
|
||||||
|
merker = Integer.parseInt(cells[i][j].getValue());
|
||||||
|
if (merker < res) {
|
||||||
|
res = merker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long max(String startCellName, String endCellName) {
|
||||||
|
int startCellRow = getRow(startCellName);
|
||||||
|
int startCellCol = getCol(startCellName);
|
||||||
|
int endCellRow = getRow(endCellName);
|
||||||
|
int endCellCol = getCol(endCellName);
|
||||||
|
|
||||||
|
long res = Long.MIN_VALUE;
|
||||||
|
long merker;
|
||||||
|
|
||||||
|
for (int i = startCellRow; i <= endCellRow; i++) {
|
||||||
|
for (int j = startCellCol; j <= endCellCol; j++) {
|
||||||
|
merker = Integer.parseInt(cells[i][j].getValue());
|
||||||
|
if (merker > res) {
|
||||||
|
res = merker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue